27 """This module defines the ReadProxy class.""" 29 from __future__
import absolute_import
31 from .persistence
import ReadProxyBase
35 """ReadProxy provides a lazy-loading object that is initialized by a 36 callback function set in ReadProxy's constructor. Adapted from 37 peak.util.proxies.LazyProxy, which was written by Phillip J. Eby 38 (peak@eby-sarna.com).""" 40 __slots__ = (
'__cache__',
'__callback__')
46 getattr(self.__subject__, attr)
49 setattr(self.__subject__, attr, val)
52 delattr(self.__subject__, attr)
55 return bool(self.__subject__)
58 return self.__subject__[arg]
61 self.__subject__[arg] = val
64 del self.__subject__[arg]
67 return self.__subject__[i:j]
70 self.__subject__[i:j] = val
73 del self.__subject__[i:j]
76 return ob
in self.__subject__
78 for name
in 'repr str hash len abs complex int long float iter oct hex'.split():
79 exec(
"def __%s__(self): return %s(self.__subject__)" % (name, name))
81 for name
in 'cmp',
'coerce',
'divmod':
82 exec(
"def __%s__(self, ob): return %s(self.__subject__, ob)" % (name,
86 (
'lt',
'<'), (
'gt',
'>'), (
'le',
'<='), (
'ge',
'>='),
87 (
'eq',
'=='), (
'ne',
'!=')
89 exec(
"def __%s__(self, ob): return self.__subject__ %s ob" % (name, op))
91 for name, op
in [(
'neg',
'-'), (
'pos',
'+'), (
'invert',
'~')]:
92 exec(
"def __%s__(self): return %s self.__subject__" % (name, op))
95 (
'or',
'|'), (
'and',
'&'), (
'xor',
'^'),
96 (
'lshift',
'<<'), (
'rshift',
'>>'),
97 (
'add',
'+'), (
'sub',
'-'), (
'mul',
'*'), (
'div',
'/'),
98 (
'mod',
'%'), (
'truediv',
'/'), (
'floordiv',
'//')
101 "def __%(name)s__(self,ob):\n" 102 " return self.__subject__ %(op)s ob\n" 104 "def __r%(name)s__(self,ob):\n" 105 " return ob %(op)s self.__subject__\n" 107 "def __i%(name)s__(self,ob):\n" 108 " self.__subject__ %(op)s=ob\n" 117 return divmod(ob, self.__subject__)
120 return pow(self.__subject__, *args)
123 self.__subject__ **= ob
127 return pow(ob, self.__subject__)
130 get_callback = ReadProxy.__callback__.__get__
131 set_callback = ReadProxy.__callback__.__set__
132 get_cache = ReadProxy.__cache__.__get__
133 set_cache = ReadProxy.__cache__.__set__
136 def _subject(self, get_cache=get_cache, set_cache=set_cache):
139 except AttributeError:
144 ReadProxy.__subject__ = property(_subject, set_cache)
def __getitem__(self, arg)
def __getslice__(self, i, j)
def __delslice__(self, i, j)
def __setattr__(self, attr, val)
def __delattr__(self, attr)
def __setitem__(self, arg, val)
def __rdivmod__(self, ob)
def __delitem__(self, arg)
def __setslice__(self, i, j, val)
def __contains__(self, ob)
def __getattr__(self, attr)