Commit 3913a125 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 2cc3912d
......@@ -759,16 +759,16 @@ def TopoEncode(tree):
# See top-level docstring for description of topology encoding.
class TopoDecodeError(Exception):
pass
def TopoDecode(text):
levelv = text.split('/') # T3/T-T/B1-T5/B-B7,8,9 -> T3 T-T B1-T5 B-B7,8,9
def TopoDecode(text, vdecode=int): # XXX vdecode - document
levelv = text.split('/') # T3/T-T/B1:a-T5/B-B7,8,9 -> T3 T-T B1:a-T5 B-B7,8,9
# build nodes from bottom-up
currentv = [] # of nodes on current level (that we are building)
bottomq = [] # of nodes below current level that we are building
# shrinks as fifo as nodes added to currentv link to bottom
while len(levelv) > 0:
level = levelv.pop() # e.g. B1-T5
tnodev = level.split('-') # e.g. B1 T5
level = levelv.pop() # e.g. B1:a-T5
tnodev = level.split('-') # e.g. B1:a T5
bottomq = currentv
currentv = []
for tnode in tnodev:
......@@ -778,14 +778,24 @@ def TopoDecode(text):
typ = Bucket
else:
raise TopoDecodeError("incorrect node %s: unknown prefix" % qq(tnode))
tkeys = tnode[1:] # e.g. '7,8,9' or ''
tkeys = tnode[1:] # e.g. '7,8,9' or '1:a,3:def' or ''
if tkeys == '':
keyv = []
else:
withV = (typ is Bucket and ':' in tkeys)
tkeyv = tkeys.split(',') # e.g. 7 8 9
keyv = [int(_) for _ in tkeyv]
keyv = []
valuev= [] if withV else None
for tkey in tkeyv:
ktxt = tkey
if withV:
ktxt, vtxt = tkey.split(':')
v = vdecode(vtxt)
valuev.append(v)
k = int(ktxt)
keyv.append(k)
if typ is Bucket:
node = Bucket(*keyv)
node = Bucket(*keyv) # XXX valuev
else:
# Tree
nchild = len(keyv) + 1
......
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