diff options
Diffstat (limited to 'Lib/xml/dom/minidom.py')
-rw-r--r-- | Lib/xml/dom/minidom.py | 54 |
1 files changed, 25 insertions, 29 deletions
diff --git a/Lib/xml/dom/minidom.py b/Lib/xml/dom/minidom.py index ad42947238..7518852798 100644 --- a/Lib/xml/dom/minidom.py +++ b/Lib/xml/dom/minidom.py @@ -177,34 +177,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): @@ -298,9 +291,10 @@ def _in_document(node): def _write_data(writer, data): "Writes datachars to writer." - data = data.replace("&", "&").replace("<", "<") - data = data.replace("\"", """).replace(">", ">") - writer.write(data) + if data: + data = data.replace("&", "&").replace("<", "<"). \ + replace("\"", """).replace(">", ">") + writer.write(data) def _get_elements_by_tagName_helper(parent, name, rc): for node in parent.childNodes: @@ -498,9 +492,9 @@ class NamedNodeMap(object): def has_key(self, key): if isinstance(key, StringTypes): - return self._attrs.has_key(key) + return key in self._attrs else: - return self._attrsNS.has_key(key) + return key in self._attrsNS def keys(self): return self._attrs.keys() @@ -782,10 +776,10 @@ class Element(Node): removeAttributeNodeNS = removeAttributeNode def hasAttribute(self, name): - return self._attrs.has_key(name) + return name in self._attrs def hasAttributeNS(self, namespaceURI, localName): - return self._attrsNS.has_key((namespaceURI, localName)) + return (namespaceURI, localName) in self._attrsNS def getElementsByTagName(self, name): return _get_elements_by_tagName_helper(self, name, NodeList()) @@ -897,6 +891,10 @@ class Childless: raise xml.dom.NotFoundErr( self.nodeName + " nodes do not have children") + def normalize(self): + # For childless nodes, normalize() has nothing to do. + pass + def replaceChild(self, newChild, oldChild): raise xml.dom.HierarchyRequestErr( self.nodeName + " nodes do not have children") @@ -1343,11 +1341,9 @@ class Notation(Identified, Childless, Node): class DOMImplementation(DOMImplementationLS): _features = [("core", "1.0"), ("core", "2.0"), - ("core", "3.0"), ("core", None), ("xml", "1.0"), ("xml", "2.0"), - ("xml", "3.0"), ("xml", None), ("ls-load", "3.0"), ("ls-load", None), @@ -1450,7 +1446,7 @@ class ElementInfo(object): return False def isId(self, aname): - """Returns true iff the named attribte is a DTD-style ID.""" + """Returns true iff the named attribute is a DTD-style ID.""" return False def isIdNS(self, namespaceURI, localName): @@ -1879,7 +1875,7 @@ def _clone_node(node, deep, newOwnerDocument): e._call_user_data_handler(operation, n, entity) else: # Note the cloning of Document and DocumentType nodes is - # implemenetation specific. minidom handles those cases + # implementation specific. minidom handles those cases # directly in the cloneNode() methods. raise xml.dom.NotSupportedErr("Cannot clone node %s" % repr(node)) |