]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Fix for PyXML bug #563399, as much as we can implement without relying on
authorFred Drake <fdrake@acm.org>
Thu, 26 Sep 2002 15:24:41 +0000 (15:24 +0000)
committerFred Drake <fdrake@acm.org>
Thu, 26 Sep 2002 15:24:41 +0000 (15:24 +0000)
a specific Expat version.
This includes fixing a test that enforced the incorrect result.

Lib/test/test_sax.py
Lib/xml/sax/expatreader.py

index 32b7609cc651db1bc4f56675f2af2c3d45a2292e..2a824950666b973d0b61b25fd51a69abb6bc4f08 100644 (file)
@@ -337,7 +337,7 @@ def test_expat_nsattrs_wattr():
 
     return attrs.getLength() == 1 and \
            attrs.getNames() == [(ns_uri, "attr")] and \
-           attrs.getQNames() == [] and \
+           attrs.getQNames() == ["ns:attr"] and \
            len(attrs) == 1 and \
            attrs.has_key((ns_uri, "attr")) and \
            attrs.keys() == [(ns_uri, "attr")] and \
index d641c191f6f9e50ac590ebcbd9217aeb7656a88d..4b81b99fbf654795ea7a18c1c84ac9f097d87448 100644 (file)
@@ -77,6 +77,7 @@ class ExpatParser(xmlreader.IncrementalParser, xmlreader.Locator):
         self._lex_handler_prop = None
         self._parsing = 0
         self._entity_stack = []
+        self._ns_stack = []
 
     # XMLReader methods
 
@@ -227,17 +228,23 @@ class ExpatParser(xmlreader.IncrementalParser, xmlreader.Locator):
             pair = tuple(pair)
 
         newattrs = {}
+        qnames = {}
         for (aname, value) in attrs.items():
             apair = string.split(aname)
             if len(apair) == 1:
                 apair = (None, aname)
+                qname = aname
             else:
                 apair = tuple(apair)
+                # XXX need to guess the prefix
+                prefix = self._ns_stack[-1][apair[0]][-1]
+                qname = "%s:%s" % (prefix, apair[1])
 
             newattrs[apair] = value
+            qnames[apair] = qname
 
         self._cont_handler.startElementNS(pair, None,
-                                          AttributesNSImpl(newattrs, {}))
+                                          AttributesNSImpl(newattrs, qnames))
 
     def end_element_ns(self, name):
         pair = string.split(name)
@@ -257,9 +264,19 @@ class ExpatParser(xmlreader.IncrementalParser, xmlreader.Locator):
         self._cont_handler.characters(data)
 
     def start_namespace_decl(self, prefix, uri):
+        if self._ns_stack:
+            d = self._ns_stack.copy()
+            if d.has_key(uri):
+                L = d[uri][:]
+                d[uri] = L
+                L.append(prefix)
+        else:
+            d = {uri: [prefix]}
+        self._ns_stack.append(d)
         self._cont_handler.startPrefixMapping(prefix, uri)
 
     def end_namespace_decl(self, prefix):
+        del self._ns_stack[-1]
         self._cont_handler.endPrefixMapping(prefix)
 
     def unparsed_entity_decl(self, name, base, sysid, pubid, notation_name):