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

.

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