[Python-checkins] python/dist/src/Lib/xml/sax expatreader.py,1.25.16.2,1.25.16.3

fdrake@users.sourceforge.net fdrake@users.sourceforge.net
Thu, 26 Sep 2002 08:24:43 -0700


Update of /cvsroot/python/python/dist/src/Lib/xml/sax
In directory usw-pr-cvs1:/tmp/cvs-serv8675/Lib/xml/sax

Modified Files:
      Tag: release22-maint
	expatreader.py 
Log Message:
Fix for PyXML bug #563399, as much as we can implement without relying on
a specific Expat version.
This includes fixing a test that enforced the incorrect result.


Index: expatreader.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/xml/sax/expatreader.py,v
retrieving revision 1.25.16.2
retrieving revision 1.25.16.3
diff -C2 -d -r1.25.16.2 -r1.25.16.3
*** expatreader.py	4 Apr 2002 19:12:50 -0000	1.25.16.2
--- expatreader.py	26 Sep 2002 15:24:40 -0000	1.25.16.3
***************
*** 78,81 ****
--- 78,82 ----
          self._parsing = 0
          self._entity_stack = []
+         self._ns_stack = []
  
      # XMLReader methods
***************
*** 228,242 ****
  
          newattrs = {}
          for (aname, value) in attrs.items():
              apair = string.split(aname)
              if len(apair) == 1:
                  apair = (None, aname)
              else:
                  apair = tuple(apair)
  
              newattrs[apair] = value
  
          self._cont_handler.startElementNS(pair, None,
!                                           AttributesNSImpl(newattrs, {}))
  
      def end_element_ns(self, name):
--- 229,249 ----
  
          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, qnames))
  
      def end_element_ns(self, name):
***************
*** 258,264 ****
--- 265,281 ----
  
      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)