* fix: long standing bug in addNode routine that prevented proper
insertion at the tail of a path * also simplify the said routine
This commit is contained in:
+5
-14
@@ -132,9 +132,8 @@ def addTagPath(dom, node, tags, newnode=None):
|
|||||||
return node
|
return node
|
||||||
|
|
||||||
def addNode(dom, node, tagpath, newnode = None):
|
def addNode(dom, node, tagpath, newnode = None):
|
||||||
"""add a new node at the end of the tree
|
"""add a new node at the end of the tree and returns it
|
||||||
if newnode is given adds that node, too
|
if newnode is given adds that node, too."""
|
||||||
returns the last node processed"""
|
|
||||||
|
|
||||||
assert type(tagpath)==str
|
assert type(tagpath)==str
|
||||||
tags = []
|
tags = []
|
||||||
@@ -147,23 +146,15 @@ def addNode(dom, node, tagpath, newnode = None):
|
|||||||
assert len(tags)>0 # we want a chain
|
assert len(tags)>0 # we want a chain
|
||||||
|
|
||||||
# iterative code to search for the path
|
# iterative code to search for the path
|
||||||
|
|
||||||
# get DOM for top node
|
while len(tags) > 1:
|
||||||
nodeList = getTagByName(node, tags[0])
|
|
||||||
|
|
||||||
if len(nodeList) == 0:
|
|
||||||
return addTagPath(dom, node, tags, newnode)
|
|
||||||
|
|
||||||
node = nodeList[len(nodeList)-1] # discard other matches
|
|
||||||
tags.pop(0)
|
|
||||||
while len(tags)>0:
|
|
||||||
tag = tags.pop(0)
|
tag = tags.pop(0)
|
||||||
nodeList = getTagByName(node, tag)
|
nodeList = getTagByName(node, tag)
|
||||||
if len(nodeList) == 0: # couldn't find
|
if len(nodeList) == 0: # couldn't find
|
||||||
tags.insert(0, tag) # put it back in
|
tags.insert(0, tag) # put it back in
|
||||||
return addTagPath(dom, node, tags, newnode)
|
return addTagPath(dom, node, tags, newnode)
|
||||||
else:
|
else:
|
||||||
node = nodeList[len(nodeList)-1]
|
node = nodeList[len(nodeList)-1] # discard other matches
|
||||||
else:
|
else:
|
||||||
# had only one tag..
|
# had only one tag..
|
||||||
return addTagPath(dom, node, tags, newnode)
|
return addTagPath(dom, node, tags, newnode)
|
||||||
|
|||||||
Reference in New Issue
Block a user