diff options
Diffstat (limited to 'mako/util.py')
-rw-r--r-- | mako/util.py | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/mako/util.py b/mako/util.py index e279f5e..f6ef125 100644 --- a/mako/util.py +++ b/mako/util.py @@ -86,8 +86,18 @@ def to_list(x, default=None): return x - - +class memoized_property(object): + """A read-only @property that is only evaluated once.""" + def __init__(self, fget, doc=None): + self.fget = fget + self.__doc__ = doc or fget.__doc__ + self.__name__ = fget.__name__ + + def __get__(self, obj, cls): + if obj is None: + return self + obj.__dict__[self.__name__] = result = self.fget(obj) + return result class SetLikeDict(dict): """a dictionary that has some setlike methods on it""" |