[Python-checkins] CVS: python/dist/src/Lib/xml/dom pulldom.py,1.22,1.23

Fred L. Drake fdrake@users.sourceforge.net
Fri, 30 Nov 2001 14:22:28 -0800


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

Modified Files:
	pulldom.py 
Log Message:
Synchronize with pulldom from PyXML (revision 1.18).

Index: pulldom.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/xml/dom/pulldom.py,v
retrieving revision 1.22
retrieving revision 1.23
diff -C2 -d -r1.22 -r1.23
*** pulldom.py	2001/07/18 15:30:25	1.22
--- pulldom.py	2001/11/30 22:22:26	1.23
***************
*** 49,53 ****
          self._xmlns_attrs.append((prefix or 'xmlns', uri))
          self._ns_contexts.append(self._current_context.copy())
!         self._current_context[uri] = prefix or ''
  
      def endPrefixMapping(self, prefix):
--- 49,53 ----
          self._xmlns_attrs.append((prefix or 'xmlns', uri))
          self._ns_contexts.append(self._current_context.copy())
!         self._current_context[uri] = prefix or None
  
      def endPrefixMapping(self, prefix):
***************
*** 212,215 ****
--- 212,217 ----
          self.parser = parser
          self.bufsize = bufsize
+         if not hasattr(self.parser, 'feed'):
+             self.getEvent = self._slurp
          self.reset()
  
***************
*** 242,245 ****
--- 244,249 ----
  
      def getEvent(self):
+         # use IncrementalParser interface, so we get the desired
+         # pull effect
          if not self.pulldom.firstEvent[1]:
              self.pulldom.lastEvent = self.pulldom.firstEvent
***************
*** 254,259 ****
          return rc
  
      def clear(self):
!         "clear(): Explicitly release parsing objects"
          self.pulldom.clear()
          del self.pulldom
--- 258,281 ----
          return rc
  
+     def _slurp(self):
+         """ Fallback replacement for getEvent() using the
+             standard SAX2 interface, which means we slurp the
+             SAX events into memory (no performance gain, but
+             we are compatible to all SAX parsers).
+         """
+         self.parser.parse(self.stream)
+         self.getEvent = self._emit
+         return self._emit()
+ 
+     def _emit(self):
+         """ Fallback replacement for getEvent() that emits
+             the events that _slurp() read previously.
+         """
+         rc = self.pulldom.firstEvent[1][0]
+         self.pulldom.firstEvent[1] = self.pulldom.firstEvent[1][1]
+         return rc
+ 
      def clear(self):
!         """clear(): Explicitly release parsing objects"""
          self.pulldom.clear()
          del self.pulldom