[Python-checkins] CVS: python/dist/src/Lib/xml/sax expatreader.py,1.22,1.23
Martin v. L?wis
loewis@users.sourceforge.net
Sun, 17 Jun 2001 00:05:45 -0700
Update of /cvsroot/python/python/dist/src/Lib/xml/sax
In directory usw-pr-cvs1:/tmp/cvs-serv27805
Modified Files:
expatreader.py
Log Message:
Synchronize with 1.13 of PyXML:
Allow application to set a new content handler and lex_prop handler during
parsing. Closes bug #433761.
Small hack to make expat be ignored in Jython.
Index: expatreader.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/xml/sax/expatreader.py,v
retrieving revision 1.22
retrieving revision 1.23
diff -C2 -r1.22 -r1.23
*** expatreader.py 2001/01/27 09:01:20 1.22
--- expatreader.py 2001/06/17 07:05:43 1.23
***************
*** 7,10 ****
--- 7,17 ----
from xml.sax._exceptions import *
+
+ # xml.parsers.expat does not raise ImportError in Jython
+ import sys
+ if sys.platform[ : 4] == "java":
+ raise SAXReaderNotAvailable("expat not available in Java", None)
+ del sys
+
try:
from xml.parsers import expat
***************
*** 47,50 ****
--- 54,64 ----
self._parser.SetBase(source.getSystemId())
+ # Redefined setContentHandle to allow changing handlers during parsing
+
+ def setContentHandler(self, handler):
+ xmlreader.IncrementalParser.setContentHandler(self, handler)
+ if self._parsing:
+ self._reset_cont_handler()
+
def getFeature(self, name):
if name == handler.feature_namespaces:
***************
*** 69,72 ****
--- 83,88 ----
if name == handler.property_lexical_handler:
self._lex_handler_prop = value
+ if self._parsing:
+ self._reset_lex_handler_prop()
else:
raise SAXNotRecognizedException("Property '%s' not recognized" % name)
***************
*** 102,105 ****
--- 118,131 ----
self._parser = None
+ def _reset_cont_handler(self):
+ self._parser.ProcessingInstructionHandler = \
+ self._cont_handler.processingInstruction
+ self._parser.CharacterDataHandler = self._cont_handler.characters
+
+ def _reset_lex_handler_prop(self):
+ self._parser.CommentHandler = self._lex_handler_prop.comment
+ self._parser.StartCdataSectionHandler = self._lex_handler_prop.startCDATA
+ self._parser.EndCdataSectionHandler = self._lex_handler_prop.endCDATA
+
def reset(self):
if self._namespaces:
***************
*** 112,118 ****
self._parser.EndElementHandler = self.end_element
! self._parser.ProcessingInstructionHandler = \
! self._cont_handler.processingInstruction
! self._parser.CharacterDataHandler = self._cont_handler.characters
self._parser.UnparsedEntityDeclHandler = self.unparsed_entity_decl
self._parser.NotationDeclHandler = self.notation_decl
--- 138,142 ----
self._parser.EndElementHandler = self.end_element
! self._reset_cont_handler()
self._parser.UnparsedEntityDeclHandler = self.unparsed_entity_decl
self._parser.NotationDeclHandler = self.notation_decl
***************
*** 122,128 ****
self._decl_handler_prop = None
if self._lex_handler_prop:
! self._parser.CommentHandler = self._lex_handler_prop.comment
! self._parser.StartCdataSectionHandler = self._lex_handler_prop.startCDATA
! self._parser.EndCdataSectionHandler = self._lex_handler_prop.endCDATA
# self._parser.DefaultHandler =
# self._parser.DefaultHandlerExpand =
--- 146,150 ----
self._decl_handler_prop = None
if self._lex_handler_prop:
! self._reset_lex_handler_prop()
# self._parser.DefaultHandler =
# self._parser.DefaultHandlerExpand =