Source code for ramverk.utils
from functools import update_wrapper
[docs]class Bunch(dict):
"""Attribute-accessible :class:`dict`."""
def __getattr__(self, name):
try:
return self[name]
except KeyError:
raise AttributeError
__setattr__ = dict.__setitem__
__delattr__ = dict.__delitem__
[docs]class request_property(object):
"""Like :class:`~werkzeug.utils.cached_property` but cached in the
object's `local` attribute, which in applications are cleared for every
request. Can be used to create lazily cached request-local
properties."""
def __init__(self, method):
update_wrapper(self, method)
self.method = method
def __get__(self, instance, owner):
if instance is None:
return self
name = self.method.__name__
if not hasattr(instance.local, name):
setattr(instance.local, name, self.method(instance))
return getattr(instance.local, name)