104 lines
3.1 KiB
Python
104 lines
3.1 KiB
Python
#@+leo-ver=4-thin
|
|
#@+node:jpenner.20090714203921.6:@thin tpers_old.py
|
|
import ZODB
|
|
import persistent
|
|
|
|
#@+others
|
|
#@+node:jpenner.20090714203921.7:def MkTransparent
|
|
def MkTransparent(value):
|
|
if type(value) == list:
|
|
return TPL(value)
|
|
elif type(value) == dict:
|
|
return TPM(value)
|
|
elif type(value) == set:
|
|
return TPS(value)
|
|
elif type(value) == tuple:
|
|
return TPT(value)
|
|
else:
|
|
return value
|
|
#@-node:jpenner.20090714203921.7:def MkTransparent
|
|
#@+node:jpenner.20090714203921.10:def RgTransparent
|
|
def RgTransparent(rg):
|
|
if rg == None: return []
|
|
return [MkTransparent(x) for x in rg]
|
|
#@-node:jpenner.20090714203921.10:def RgTransparent
|
|
#@+node:jpenner.20090714203921.11:def MpTransparent
|
|
def MpTransparent(mp):
|
|
if isinstance(mp, TPM): return mp
|
|
mpNew = {}
|
|
if mp != None:
|
|
for k,v in mp.iteritems():
|
|
mpNew[k] = MkTransparent(v)
|
|
return mpNew
|
|
#@-node:jpenner.20090714203921.11:def MpTransparent
|
|
#@+node:jpenner.20090714203921.8:class TPrs
|
|
class TPrs(persistent.Persistent):
|
|
__prs_setattr = persistent.Persistent.__setattr__
|
|
|
|
def __setattr__(self, name, value):
|
|
self.__prs_setattr(name, MkTransparent(value))
|
|
#@-node:jpenner.20090714203921.8:class TPrs
|
|
#@+node:jpenner.20090714203921.9:class TPL
|
|
class TPL(clsList):
|
|
__pl_setitem = clsList.__setitem__
|
|
__pl_setslice = clsList.__setslice__
|
|
__pl_iadd = clsList.__iadd__
|
|
__pl_append = clsList.append
|
|
__pl_insert = clsList.insert
|
|
__pl_extend = clsList.extend
|
|
|
|
def __init__(self, rg = None):
|
|
clsList.__init__(self, RgTransparent(rg))
|
|
|
|
def __setitem__(self, i, item):
|
|
return self.__pl_setitem(i, MkTransparent(item))
|
|
|
|
def __setslice__(self, i, j, other):
|
|
return self.__pl_setslice(i, j, RgTransparent(other))
|
|
|
|
def __iadd__(self, other):
|
|
return self.__pl_iadd(RgTransparent(other))
|
|
|
|
def append(self, item):
|
|
return self.__pl_append(MkTransparent(item))
|
|
|
|
def insert(self, i, item):
|
|
return self.__pl_insert(i, MkTransparent(item))
|
|
|
|
def extend(self, other):
|
|
return self.__pl_extend(RgTransparent(other))
|
|
|
|
def __reduce__(self):
|
|
return (MkTransparent, ([MkPersistable(x) for x in self],))
|
|
|
|
# Strip weak references rather than replacing them with None
|
|
class TPLS(TPL):
|
|
def __reduce__(self):
|
|
return (MkTransparent, ([x for x in self if FPersist(x)],))
|
|
#@-node:jpenner.20090714203921.9:class TPL
|
|
#@+node:jpenner.20090714203921.12:class TPM
|
|
class TPM(clsDict):
|
|
__pm_setitem = clsDict.__setitem__
|
|
__pm_update = clsDict.update
|
|
|
|
def __init__(self, *rgarg, **kwarg):
|
|
clsDict.__init__(self, MpTransparent(dict(*rgarg, **kwarg)))
|
|
|
|
def __setitem__(self, k, v):
|
|
return self.__pm_setitem(k, MkTransparent(v))
|
|
|
|
def update(self, other, **kwargs):
|
|
return self.__pm_update(MpTransparent(other), **MpTransparent(kwargs))
|
|
|
|
def __reduce__(self):
|
|
mp = {}
|
|
for k, v in self.iteritems():
|
|
if FPersist(k):
|
|
mp[k] = MkPersistable(v)
|
|
return (MkTransparent, (mp,))
|
|
|
|
#@-node:jpenner.20090714203921.12:class TPM
|
|
#@-others
|
|
#@-node:jpenner.20090714203921.6:@thin tpers_old.py
|
|
#@-leo
|