Commit 1ac0d8f1 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 08a764fe
...@@ -100,6 +100,43 @@ from BTrees import LOBTree ...@@ -100,6 +100,43 @@ from BTrees import LOBTree
LOBTree.LOBTree = XLOTree LOBTree.LOBTree = XLOTree
# ZConn represent treegen-level connection to ZODB.
# XXX high-level wrapper around zconn.
class ZConn(object):
# XXX +.zstor
# .zconn
# .valdict = zconn.root['treegen/values'] = {} v -> ZBlk(v)
# XXX -> free function? (e.g. zopen(zstor)) ?
def __init__(zstor):
# root['treegen/values'] = {} v -> ZBlk(v)
valdict = root['treegen/values'] = PersistentMapping()
valv = b'abcdefghi'
for v in valv:
zblk = ZBlk()
zblk.setblkdata(v)
valdict[v] = zblk
commit('treegen/values -> %r' % valv)
def close(self):
self.zconn.close()
# vdecode(vtxt) -> vobj decodes value text into value object, e.g. 'a' -> ZBlk(a)
# vencode(vobj) -> vtxt encodes value object into value text, e.g. ZBlk(a) -> 'a'
def vdecode(self, vtxt): # -> vobj
return self.valdict[vtxt]
def vencode(self, vobj): # -> vtxt
for (k,v) in self.valdict.items():
if v is vobj:
return k
raise KeyError("%r not found in value registry" % (vobj,))
# XXX doc
@func
def Trees(zstor, r):
for l in r.readlines():
# AllStructs generates subset of all possible tree changes in # AllStructs generates subset of all possible tree changes in
# between kv1 and kv2. See top-level documentation for details. # between kv1 and kv2. See top-level documentation for details.
@func @func
...@@ -114,14 +151,15 @@ def AllStructs(zstor, kv1txt, kv2txt, n, seed=None): ...@@ -114,14 +151,15 @@ def AllStructs(zstor, kv1txt, kv2txt, n, seed=None):
print("# seed=%d" % seed) print("# seed=%d" % seed)
random.seed(seed) random.seed(seed)
# root['treedelta/values'] = {} v -> ZBlk(v) """
valdict = root['treedelta/values'] = PersistentMapping() # root['treegen/values'] = {} v -> ZBlk(v)
valdict = root['treegen/values'] = PersistentMapping()
valv = b'abcdefghi' valv = b'abcdefghi'
for v in valv: for v in valv:
zblk = ZBlk() zblk = ZBlk()
zblk.setblkdata(v) zblk.setblkdata(v)
valdict[v] = zblk valdict[v] = zblk
commit('treedelta/values -> %r' % valv) commit('treegen/values -> %r' % valv)
# vdecode(vtxt) -> vobj decodes value text into value object, e.g. 'a' -> ZBlk(a) # vdecode(vtxt) -> vobj decodes value text into value object, e.g. 'a' -> ZBlk(a)
# vencode(vobj) -> vtxt encodes value object into value text, e.g. ZBlk(a) -> 'a' # vencode(vobj) -> vtxt encodes value object into value text, e.g. ZBlk(a) -> 'a'
...@@ -132,6 +170,7 @@ def AllStructs(zstor, kv1txt, kv2txt, n, seed=None): ...@@ -132,6 +170,7 @@ def AllStructs(zstor, kv1txt, kv2txt, n, seed=None):
if v is vobj: if v is vobj:
return k return k
raise KeyError("%r not found in value registry" % (vobj,)) raise KeyError("%r not found in value registry" % (vobj,))
"""
kv1 = kvDecode(kv1txt, vdecode) kv1 = kvDecode(kv1txt, vdecode)
kv2 = kvDecode(kv2txt, vdecode) kv2 = kvDecode(kv2txt, vdecode)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment