summaryrefslogtreecommitdiffstats
path: root/Lib/xml/dom
diff options
context:
space:
mode:
authorR. David Murray <rdmurray@bitdance.com>2009-04-09 22:16:43 (GMT)
committerR. David Murray <rdmurray@bitdance.com>2009-04-09 22:16:43 (GMT)
commitdc6da8abda6e9faeb34b53520563eed21d42e7e5 (patch)
treed838c98db711d189ccbbe10cdcf38ab8db059541 /Lib/xml/dom
parenta6191803545927421de2d5a7d9b7a7a1034a363c (diff)
downloadcpython-dc6da8abda6e9faeb34b53520563eed21d42e7e5.zip
cpython-dc6da8abda6e9faeb34b53520563eed21d42e7e5.tar.gz
cpython-dc6da8abda6e9faeb34b53520563eed21d42e7e5.tar.bz2
Merged revisions 71414 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk ........ r71414 | r.david.murray | 2009-04-09 17:54:50 -0400 (Thu, 09 Apr 2009) | 3 lines Issue #2170: refactored xml.dom.minidom.normalize, increasing both its clarity and its speed. ........
Diffstat (limited to 'Lib/xml/dom')
-rw-r--r--Lib/xml/dom/minidom.py29
1 files changed, 11 insertions, 18 deletions
diff --git a/Lib/xml/dom/minidom.py b/Lib/xml/dom/minidom.py
index 489ae52..77a44f5 100644
--- a/Lib/xml/dom/minidom.py
+++ b/Lib/xml/dom/minidom.py
@@ -179,34 +179,27 @@ class Node(xml.dom.Node):
L = []
for child in self.childNodes:
if child.nodeType == Node.TEXT_NODE:
- data = child.data
- if data and L and L[-1].nodeType == child.nodeType:
+ if not child.data:
+ # empty text node; discard
+ if L:
+ L[-1].nextSibling = child.nextSibling
+ if child.nextSibling:
+ child.nextSibling.previousSibling = child.previousSibling
+ child.unlink()
+ elif L and L[-1].nodeType == child.nodeType:
# collapse text node
node = L[-1]
node.data = node.data + child.data
node.nextSibling = child.nextSibling
+ if child.nextSibling:
+ child.nextSibling.previousSibling = node
child.unlink()
- elif data:
- if L:
- L[-1].nextSibling = child
- child.previousSibling = L[-1]
- else:
- child.previousSibling = None
- L.append(child)
else:
- # empty text node; discard
- child.unlink()
+ L.append(child)
else:
- if L:
- L[-1].nextSibling = child
- child.previousSibling = L[-1]
- else:
- child.previousSibling = None
L.append(child)
if child.nodeType == Node.ELEMENT_NODE:
child.normalize()
- if L:
- L[-1].nextSibling = None
self.childNodes[:] = L
def cloneNode(self, deep):