Ignore:
Timestamp:
Mar 19, 2014, 11:31:01 PM (11 years ago)
Author:
dmik
Message:

python: Merge vendor 2.7.6 to trunk.

Location:
python/trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • python/trunk

  • python/trunk/Lib/xml/dom/domreg.py

    r2 r391  
    5858    elif name:
    5959        return registered[name]()
    60     elif os.environ.has_key("PYTHON_DOM"):
     60    elif "PYTHON_DOM" in os.environ:
    6161        return getDOMImplementation(name = os.environ["PYTHON_DOM"])
    6262
  • python/trunk/Lib/xml/dom/expatbuilder.py

    r2 r391  
    243243            doctypeName, publicId, systemId)
    244244        doctype.ownerDocument = self.document
    245         self.document.childNodes.append(doctype)
     245        _append_child(self.document, doctype)
    246246        self.document.doctype = doctype
    247247        if self._filter and self._filter.acceptNode(doctype) == FILTER_REJECT:
  • python/trunk/Lib/xml/dom/minicompat.py

    r2 r391  
    77#   NodeList      -- lightest possible NodeList implementation
    88#
    9 #   EmptyNodeList -- lightest possible NodeList that is guarateed to
     9#   EmptyNodeList -- lightest possible NodeList that is guaranteed to
    1010#                    remain empty (immutable)
    1111#
  • 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
     3Namespaces and other minor Level 2 features are also supported.
    34
    45parse("foo.xml")
     
    178179        for child in self.childNodes:
    179180            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:
    182189                    # collapse text node
    183190                    node = L[-1]
    184191                    node.data = node.data + child.data
    185192                    node.nextSibling = child.nextSibling
     193                    if child.nextSibling:
     194                        child.nextSibling.previousSibling = node
    186195                    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:
    193197                    L.append(child)
    194                 else:
    195                     # empty text node; discard
    196                     child.unlink()
    197198            else:
    198                 if L:
    199                     L[-1].nextSibling = child
    200                     child.previousSibling = L[-1]
    201                 else:
    202                     child.previousSibling = None
    203199                L.append(child)
    204200                if child.nodeType == Node.ELEMENT_NODE:
    205201                    child.normalize()
    206         if L:
    207             L[-1].nextSibling = None
    208202        self.childNodes[:] = L
    209203
     
    299293def _write_data(writer, data):
    300294    "Writes datachars to writer."
    301     data = data.replace("&", "&amp;").replace("<", "&lt;")
    302     data = data.replace("\"", "&quot;").replace(">", "&gt;")
    303     writer.write(data)
     295    if data:
     296        data = data.replace("&", "&amp;").replace("<", "&lt;"). \
     297                    replace("\"", "&quot;").replace(">", "&gt;")
     298        writer.write(data)
    304299
    305300def _get_elements_by_tagName_helper(parent, name, rc):
     
    363358    def _get_localName(self):
    364359        return self.nodeName.split(":", 1)[-1]
    365 
    366     def _get_name(self):
    367         return self.name
    368360
    369361    def _get_specified(self):
     
    499491    def has_key(self, key):
    500492        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
    504496
    505497    def keys(self):
     
    783775
    784776    def hasAttribute(self, name):
    785         return self._attrs.has_key(name)
     777        return name in self._attrs
    786778
    787779    def hasAttributeNS(self, namespaceURI, localName):
    788         return self._attrsNS.has_key((namespaceURI, localName))
     780        return (namespaceURI, localName) in self._attrsNS
    789781
    790782    def getElementsByTagName(self, name):
     
    813805            writer.write("\"")
    814806        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))
    819817        else:
    820818            writer.write("/>%s"%(newl))
     
    897895        raise xml.dom.NotFoundErr(
    898896            self.nodeName + " nodes do not have children")
     897
     898    def normalize(self):
     899        # For childless nodes, normalize() has nothing to do.
     900        pass
    899901
    900902    def replaceChild(self, newChild, oldChild):
     
    10341036
    10351037    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))
    10371039
    10381040    # DOM Level 3 (WD 9 April 2002)
     
    13441346    _features = [("core", "1.0"),
    13451347                 ("core", "2.0"),
    1346                  ("core", "3.0"),
    13471348                 ("core", None),
    13481349                 ("xml", "1.0"),
    13491350                 ("xml", "2.0"),
    1350                  ("xml", "3.0"),
    13511351                 ("xml", None),
    13521352                 ("ls-load", "3.0"),
     
    14511451
    14521452    def isId(self, aname):
    1453         """Returns true iff the named attribte is a DTD-style ID."""
     1453        """Returns true iff the named attribute is a DTD-style ID."""
    14541454        return False
    14551455
     
    18801880    else:
    18811881        # Note the cloning of Document and DocumentType nodes is
    1882         # implemenetation specific.  minidom handles those cases
     1882        # implementation specific.  minidom handles those cases
    18831883        # directly in the cloneNode() methods.
    18841884        raise xml.dom.NotSupportedErr("Cannot clone node %s" % repr(node))
  • python/trunk/Lib/xml/dom/xmlbuilder.py

    r2 r391  
    9292    def canSetFeature(self, name, state):
    9393        key = (_name_xform(name), state and 1 or 0)
    94         return self._settings.has_key(key)
     94        return key in self._settings
    9595
    9696    # This dictionary maps from (feature,value) to a list of
     
    248248    def _guess_media_encoding(self, source):
    249249        info = source.byteStream.info()
    250         if info.has_key("Content-Type"):
     250        if "Content-Type" in info:
    251251            for param in info.getplist():
    252252                if param.startswith("charset="):
Note: See TracChangeset for help on using the changeset viewer.