diff options
Diffstat (limited to 'repoze/bfg/decorator.py')
| -rw-r--r-- | repoze/bfg/decorator.py | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/repoze/bfg/decorator.py b/repoze/bfg/decorator.py new file mode 100644 index 000000000..69c1e65e2 --- /dev/null +++ b/repoze/bfg/decorator.py @@ -0,0 +1,15 @@ +class reify(object): + + """ Put the result of a method which uses this (non-data) + descriptor decorator in the instance dict after the first call, + effectively replacing the decorator with an instance variable.""" + + def __init__(self, wrapped): + self.wrapped = wrapped + + def __get__(self, inst, objtype=None): + if inst is None: + return self + val = self.wrapped(inst) + setattr(inst, self.wrapped.__name__, val) + return val |
