Changeset 391 for python/trunk/Lib/xml/dom
- Timestamp:
- Mar 19, 2014, 11:31:01 PM (11 years ago)
- Location:
- python/trunk
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
python/trunk
-
Property svn:mergeinfo
set to
/python/vendor/Python-2.7.6 merged eligible /python/vendor/current merged eligible
-
Property svn:mergeinfo
set to
-
python/trunk/Lib/xml/dom/domreg.py
r2 r391 58 58 elif name: 59 59 return registered[name]() 60 elif os.environ.has_key("PYTHON_DOM"):60 elif "PYTHON_DOM" in os.environ: 61 61 return getDOMImplementation(name = os.environ["PYTHON_DOM"]) 62 62 -
python/trunk/Lib/xml/dom/expatbuilder.py
r2 r391 243 243 doctypeName, publicId, systemId) 244 244 doctype.ownerDocument = self.document 245 self.document.childNodes.append(doctype)245 _append_child(self.document, doctype) 246 246 self.document.doctype = doctype 247 247 if self._filter and self._filter.acceptNode(doctype) == FILTER_REJECT: -
python/trunk/Lib/xml/dom/minicompat.py
r2 r391 7 7 # NodeList -- lightest possible NodeList implementation 8 8 # 9 # EmptyNodeList -- lightest possible NodeList that is guara teed to9 # EmptyNodeList -- lightest possible NodeList that is guaranteed to 10 10 # remain empty (immutable) 11 11 # -
python/trunk/Lib/xml/dom/minidom.py
r2 r391 1 """\ 2 minidom.py -- a lightweight DOM implementation. 1 """Simple implementation of the Level 1 DOM. 2 3 Namespaces and other minor Level 2 features are also supported. 3 4 4 5 parse("foo.xml") … … 178 179 for child in self.childNodes: 179 180 if child.nodeType == Node.TEXT_NODE: 180 data = child.data 181 if data and L and L[-1].nodeType == child.nodeType: 181 if not child.data: 182 # empty text node; discard 183 if L: 184 L[-1].nextSibling = child.nextSibling 185 if child.nextSibling: 186 child.nextSibling.previousSibling = child.previousSibling 187 child.unlink() 188 elif L and L[-1].nodeType == child.nodeType: 182 189 # collapse text node 183 190 node = L[-1] 184 191 node.data = node.data + child.data 185 192 node.nextSibling = child.nextSibling 193 if child.nextSibling: 194 child.nextSibling.previousSibling = node 186 195 child.unlink() 187 elif data: 188 if L: 189 L[-1].nextSibling = child 190 child.previousSibling = L[-1] 191 else: 192 child.previousSibling = None 196 else: 193 197 L.append(child) 194 else:195 # empty text node; discard196 child.unlink()197 198 else: 198 if L:199 L[-1].nextSibling = child200 child.previousSibling = L[-1]201 else:202 child.previousSibling = None203 199 L.append(child) 204 200 if child.nodeType == Node.ELEMENT_NODE: 205 201 child.normalize() 206 if L:207 L[-1].nextSibling = None208 202 self.childNodes[:] = L 209 203 … … 299 293 def _write_data(writer, data): 300 294 "Writes datachars to writer." 301 data = data.replace("&", "&").replace("<", "<") 302 data = data.replace("\"", """).replace(">", ">") 303 writer.write(data) 295 if data: 296 data = data.replace("&", "&").replace("<", "<"). \ 297 replace("\"", """).replace(">", ">") 298 writer.write(data) 304 299 305 300 def _get_elements_by_tagName_helper(parent, name, rc): … … 363 358 def _get_localName(self): 364 359 return self.nodeName.split(":", 1)[-1] 365 366 def _get_name(self):367 return self.name368 360 369 361 def _get_specified(self): … … 499 491 def has_key(self, key): 500 492 if isinstance(key, StringTypes): 501 return self._attrs.has_key(key)502 else: 503 return self._attrsNS.has_key(key)493 return key in self._attrs 494 else: 495 return key in self._attrsNS 504 496 505 497 def keys(self): … … 783 775 784 776 def hasAttribute(self, name): 785 return self._attrs.has_key(name)777 return name in self._attrs 786 778 787 779 def hasAttributeNS(self, namespaceURI, localName): 788 return self._attrsNS.has_key((namespaceURI, localName))780 return (namespaceURI, localName) in self._attrsNS 789 781 790 782 def getElementsByTagName(self, name): … … 813 805 writer.write("\"") 814 806 if self.childNodes: 815 writer.write(">%s"%(newl)) 816 for node in self.childNodes: 817 node.writexml(writer,indent+addindent,addindent,newl) 818 writer.write("%s</%s>%s" % (indent,self.tagName,newl)) 807 writer.write(">") 808 if (len(self.childNodes) == 1 and 809 self.childNodes[0].nodeType == Node.TEXT_NODE): 810 self.childNodes[0].writexml(writer, '', '', '') 811 else: 812 writer.write(newl) 813 for node in self.childNodes: 814 node.writexml(writer, indent+addindent, addindent, newl) 815 writer.write(indent) 816 writer.write("</%s>%s" % (self.tagName, newl)) 819 817 else: 820 818 writer.write("/>%s"%(newl)) … … 897 895 raise xml.dom.NotFoundErr( 898 896 self.nodeName + " nodes do not have children") 897 898 def normalize(self): 899 # For childless nodes, normalize() has nothing to do. 900 pass 899 901 900 902 def replaceChild(self, newChild, oldChild): … … 1034 1036 1035 1037 def writexml(self, writer, indent="", addindent="", newl=""): 1036 _write_data(writer, "%s%s%s" %(indent, self.data, newl))1038 _write_data(writer, "%s%s%s" % (indent, self.data, newl)) 1037 1039 1038 1040 # DOM Level 3 (WD 9 April 2002) … … 1344 1346 _features = [("core", "1.0"), 1345 1347 ("core", "2.0"), 1346 ("core", "3.0"),1347 1348 ("core", None), 1348 1349 ("xml", "1.0"), 1349 1350 ("xml", "2.0"), 1350 ("xml", "3.0"),1351 1351 ("xml", None), 1352 1352 ("ls-load", "3.0"), … … 1451 1451 1452 1452 def isId(self, aname): 1453 """Returns true iff the named attrib te is a DTD-style ID."""1453 """Returns true iff the named attribute is a DTD-style ID.""" 1454 1454 return False 1455 1455 … … 1880 1880 else: 1881 1881 # Note the cloning of Document and DocumentType nodes is 1882 # implemen etation specific. minidom handles those cases1882 # implementation specific. minidom handles those cases 1883 1883 # directly in the cloneNode() methods. 1884 1884 raise xml.dom.NotSupportedErr("Cannot clone node %s" % repr(node)) -
python/trunk/Lib/xml/dom/xmlbuilder.py
r2 r391 92 92 def canSetFeature(self, name, state): 93 93 key = (_name_xform(name), state and 1 or 0) 94 return self._settings.has_key(key)94 return key in self._settings 95 95 96 96 # This dictionary maps from (feature,value) to a list of … … 248 248 def _guess_media_encoding(self, source): 249 249 info = source.byteStream.info() 250 if info.has_key("Content-Type"):250 if "Content-Type" in info: 251 251 for param in info.getplist(): 252 252 if param.startswith("charset="):
Note:
See TracChangeset
for help on using the changeset viewer.