* fix: remove redundant dom args from add routines
* I told you to expect breakage. Mwahahaha!
This commit is contained in:
+9
-8
@@ -115,23 +115,24 @@ def getAllNodes(node, tagPath):
|
|||||||
|
|
||||||
return nodeList
|
return nodeList
|
||||||
|
|
||||||
def createTagPath(dom, node, tags):
|
def createTagPath(node, tags):
|
||||||
"""create new child at the end of a tag chain starting from node
|
"""create new child at the end of a tag chain starting from node
|
||||||
no matter what"""
|
no matter what"""
|
||||||
if len(tags)==0:
|
if len(tags)==0:
|
||||||
return node
|
return node
|
||||||
|
dom = node.ownerDocument
|
||||||
for tag in tags:
|
for tag in tags:
|
||||||
node = node.appendChild(dom.createElement(tag))
|
node = node.appendChild(dom.createElement(tag))
|
||||||
return node
|
return node
|
||||||
|
|
||||||
def addTagPath(dom, node, tags, newnode=None):
|
def addTagPath(node, tags, newnode=None):
|
||||||
"""add newnode at the end of a tag chain, smart one"""
|
"""add newnode at the end of a tag chain, smart one"""
|
||||||
node = createTagPath(dom, node, tags)
|
node = createTagPath(node, tags)
|
||||||
if newnode: # node to add specified
|
if newnode: # node to add specified
|
||||||
node.appendChild(newnode)
|
node.appendChild(newnode)
|
||||||
return node
|
return node
|
||||||
|
|
||||||
def addNode(dom, node, tagpath, newnode = None):
|
def addNode(node, tagpath, newnode = None):
|
||||||
"""add a new node at the end of the tree and returns it
|
"""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."""
|
||||||
|
|
||||||
@@ -140,7 +141,7 @@ def addNode(dom, node, tagpath, newnode = None):
|
|||||||
if tagpath != "":
|
if tagpath != "":
|
||||||
tags = tagpath.split('/') # tag chain
|
tags = tagpath.split('/') # tag chain
|
||||||
else:
|
else:
|
||||||
addTagPath(dom, node, [], newnode)
|
addTagPath(node, [], newnode)
|
||||||
return node #FIXME: is this correct!?!?
|
return node #FIXME: is this correct!?!?
|
||||||
|
|
||||||
assert len(tags)>0 # we want a chain
|
assert len(tags)>0 # we want a chain
|
||||||
@@ -152,12 +153,12 @@ def addNode(dom, node, tagpath, newnode = None):
|
|||||||
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(node, tags, newnode)
|
||||||
else:
|
else:
|
||||||
node = nodeList[len(nodeList)-1] # discard other matches
|
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(node, tags, newnode)
|
||||||
|
|
||||||
return node
|
return node
|
||||||
|
|
||||||
@@ -169,4 +170,4 @@ def newTextNode(node, text):
|
|||||||
|
|
||||||
def addText(node, tagPath, text):
|
def addText(node, tagPath, text):
|
||||||
newnode = newTextNode(node, text)
|
newnode = newTextNode(node, text)
|
||||||
addNode(node.ownerDocument, node, tagPath, newnode)
|
addNode(node, tagPath, newnode)
|
||||||
|
|||||||
+3
-4
@@ -623,7 +623,7 @@ class autoxml(oo.autosuper):
|
|||||||
if l and len(l) > 0:
|
if l and len(l) > 0:
|
||||||
for item in l:
|
for item in l:
|
||||||
if list_tagpath:
|
if list_tagpath:
|
||||||
listnode = addNode(dom, node, list_tagpath)
|
listnode = addNode(node, list_tagpath)
|
||||||
else:
|
else:
|
||||||
listnode = node
|
listnode = node
|
||||||
encode_item(xml, listnode, item, errs)
|
encode_item(xml, listnode, item, errs)
|
||||||
@@ -803,13 +803,12 @@ class XmlFile(object):
|
|||||||
def addNode(self, tagPath, newnode = None):
|
def addNode(self, tagPath, newnode = None):
|
||||||
"this adds the newnode under given tag path"
|
"this adds the newnode under given tag path"
|
||||||
self.verifyRootTag()
|
self.verifyRootTag()
|
||||||
return addNode(self.dom, self.dom.documentElement, tagPath,
|
return addNode(self.dom.documentElement, tagPath, newnode)
|
||||||
newnode)
|
|
||||||
|
|
||||||
def addNodeUnder(self, node, tagPath, newnode = None):
|
def addNodeUnder(self, node, tagPath, newnode = None):
|
||||||
"this adds the new stuff under node and then following tag path"
|
"this adds the new stuff under node and then following tag path"
|
||||||
self.verifyRootTag()
|
self.verifyRootTag()
|
||||||
return addNode(self.dom, node, tagPath, newnode)
|
return addNode(node, tagPath, newnode)
|
||||||
|
|
||||||
def addChild(self, newnode):
|
def addChild(self, newnode):
|
||||||
"add a new child node right under root element document"
|
"add a new child node right under root element document"
|
||||||
|
|||||||
Reference in New Issue
Block a user