diff options
Diffstat (limited to 'Lib/xml/dom')
-rw-r--r-- | Lib/xml/dom/domreg.py | 2 | ||||
-rw-r--r-- | Lib/xml/dom/expatbuilder.py | 2 | ||||
-rw-r--r-- | Lib/xml/dom/minicompat.py | 2 | ||||
-rw-r--r-- | Lib/xml/dom/minidom.py | 54 | ||||
-rw-r--r-- | Lib/xml/dom/xmlbuilder.py | 4 |
5 files changed, 30 insertions, 34 deletions
diff --git a/Lib/xml/dom/domreg.py b/Lib/xml/dom/domreg.py index 684c436016..ec3acdf9c1 100644 --- a/Lib/xml/dom/domreg.py +++ b/Lib/xml/dom/domreg.py @@ -57,7 +57,7 @@ def getDOMImplementation(name = None, features = ()): return mod.getDOMImplementation() elif name: return registered[name]() - elif os.environ.has_key("PYTHON_DOM"): + elif "PYTHON_DOM" in os.environ: return getDOMImplementation(name = os.environ["PYTHON_DOM"]) # User did not specify a name, try implementations in arbitrary diff --git a/Lib/xml/dom/expatbuilder.py b/Lib/xml/dom/expatbuilder.py index a2f8a33834..4fba87585f 100644 --- a/Lib/xml/dom/expatbuilder.py +++ b/Lib/xml/dom/expatbuilder.py @@ -242,7 +242,7 @@ class ExpatBuilder: doctype = self.document.implementation.createDocumentType( doctypeName, publicId, systemId) doctype.ownerDocument = self.document - self.document.childNodes.append(doctype) + _append_child(self.document, doctype) self.document.doctype = doctype if self._filter and self._filter.acceptNode(doctype) == FILTER_REJECT: self.document.doctype = None diff --git a/Lib/xml/dom/minicompat.py b/Lib/xml/dom/minicompat.py index d491fb69fc..de4cb4f78a 100644 --- a/Lib/xml/dom/minicompat.py +++ b/Lib/xml/dom/minicompat.py @@ -6,7 +6,7 @@ # # NodeList -- lightest possible NodeList implementation # -# EmptyNodeList -- lightest possible NodeList that is guarateed to +# EmptyNodeList -- lightest possible NodeList that is guaranteed to # remain empty (immutable) # # StringTypes -- tuple of defined string types 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)) diff --git a/Lib/xml/dom/xmlbuilder.py b/Lib/xml/dom/xmlbuilder.py index ac1d448f01..dc7c5d4705 100644 --- a/Lib/xml/dom/xmlbuilder.py +++ b/Lib/xml/dom/xmlbuilder.py @@ -91,7 +91,7 @@ class DOMBuilder: def canSetFeature(self, name, state): key = (_name_xform(name), state and 1 or 0) - return self._settings.has_key(key) + return key in self._settings # This dictionary maps from (feature,value) to a list of # (option,value) pairs that should be set on the Options object. @@ -247,7 +247,7 @@ class DOMEntityResolver(object): def _guess_media_encoding(self, source): info = source.byteStream.info() - if info.has_key("Content-Type"): + if "Content-Type" in info: for param in info.getplist(): if param.startswith("charset="): return param.split("=", 1)[1].lower() |