/usr/share/pyshared/epsilon/remember.py is in python-epsilon 0.7.0-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | # -*- test-case-name: epsilon.test.test_remember -*-
"""
This module implements a utility for managing the lifecycle of attributes
related to a particular object.
"""
from epsilon.structlike import record
class remembered(record('creationFunction')):
"""
This descriptor decorator is applied to a function to create an attribute
which will be created on-demand, but remembered for the lifetime of the
instance to which it is attached. Subsequent accesses of the attribute
will return the remembered value.
@ivar creationFunction: the decorated function, to be called to create the
value. This should be a 1-argument callable, that takes only a 'self'
parameter, like a method.
"""
value = None
def __get__(self, oself, type):
"""
Retrieve the value if already cached, otherwise, call the
C{creationFunction} to create it.
"""
remembername = "_remembered_" + self.creationFunction.func_name
rememberedval = oself.__dict__.get(remembername, None)
if rememberedval is not None:
return rememberedval
rememberme = self.creationFunction(oself)
oself.__dict__[remembername] = rememberme
return rememberme
__all__ = ['remembered']
|