Back to index

moin  1.9.0~rc2
Public Member Functions | Public Attributes | Private Attributes
MoinMoin.support.werkzeug.utils.cached_property Class Reference

List of all members.

Public Member Functions

def __init__
def __get__
def __set__

Public Attributes

 func
 writeable

Private Attributes

 __name__
 __doc__

Detailed Description

A decorator that converts a function into a lazy property.  The
function wrapped is called the first time to retrieve the result
and than that calculated result is used the next time you access
the value::

    class Foo(object):

        @cached_property
        def foo(self):
            # calculate something important here
            return 42

.. versionchanged:: 0.5
   cached properties are now optionally writeable.

Definition at line 653 of file utils.py.


Constructor & Destructor Documentation

def MoinMoin.support.werkzeug.utils.cached_property.__init__ (   self,
  func,
  name = None,
  doc = None,
  writeable = False 
)

Definition at line 670 of file utils.py.

00670 
00671     def __init__(self, func, name=None, doc=None, writeable=False):
00672         self.func = func
00673         self.writeable = writeable
00674         self.__name__ = name or func.__name__
00675         self.__doc__ = doc or func.__doc__


Member Function Documentation

def MoinMoin.support.werkzeug.utils.cached_property.__get__ (   self,
  obj,
  type = None 
)

Definition at line 676 of file utils.py.

00676 
00677     def __get__(self, obj, type=None):
00678         if obj is None:
00679             return self
00680         value = obj.__dict__.get(self.__name__, _missing)
00681         if value is _missing:
00682             value = self.func(obj)
00683             obj.__dict__[self.__name__] = value
00684         return value

def MoinMoin.support.werkzeug.utils.cached_property.__set__ (   self,
  obj,
  value 
)

Definition at line 685 of file utils.py.

00685 
00686     def __set__(self, obj, value):
00687         if not self.writeable:
00688             raise TypeError('read only attribute')
00689         obj.__dict__[self.__name__] = value
00690 


Member Data Documentation

Definition at line 674 of file utils.py.

Definition at line 673 of file utils.py.

Definition at line 671 of file utils.py.

Definition at line 672 of file utils.py.


The documentation for this class was generated from the following file: