summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorMartin v. Löwis <martin@v.loewis.de>2001-06-17 07:05:43 (GMT)
committerMartin v. Löwis <martin@v.loewis.de>2001-06-17 07:05:43 (GMT)
commitfb73bb129b2ccbd9644709ac8eeac1d5e7f0a32d (patch)
treeb50ea2a5ad8e40f7dd3d02d2ab79322297178b73 /Lib
parentd083839fb4f44ff66792d80f7a71863600ca4638 (diff)
downloadcpython-fb73bb129b2ccbd9644709ac8eeac1d5e7f0a32d.zip
cpython-fb73bb129b2ccbd9644709ac8eeac1d5e7f0a32d.tar.gz
cpython-fb73bb129b2ccbd9644709ac8eeac1d5e7f0a32d.tar.bz2
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.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/xml/sax/expatreader.py34
1 files changed, 28 insertions, 6 deletions
diff --git a/Lib/xml/sax/expatreader.py b/Lib/xml/sax/expatreader.py
index b1d4c97..b8a31ff 100644
--- a/Lib/xml/sax/expatreader.py
+++ b/Lib/xml/sax/expatreader.py
@@ -6,6 +6,13 @@ pyexpat.__version__ == '2.22'.
version = "0.20"
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
except ImportError:
@@ -46,6 +53,13 @@ class ExpatParser(xmlreader.IncrementalParser, xmlreader.Locator):
if source.getSystemId() != None:
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:
return self._namespaces
@@ -68,6 +82,8 @@ class ExpatParser(xmlreader.IncrementalParser, xmlreader.Locator):
def setProperty(self, name, value):
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)
@@ -101,6 +117,16 @@ class ExpatParser(xmlreader.IncrementalParser, xmlreader.Locator):
# break cycle created by expat handlers pointing to our methods
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:
self._parser = expat.ParserCreate(None, " ")
@@ -111,9 +137,7 @@ class ExpatParser(xmlreader.IncrementalParser, xmlreader.Locator):
self._parser.StartElementHandler = self.start_element
self._parser.EndElementHandler = self.end_element
- self._parser.ProcessingInstructionHandler = \
- self._cont_handler.processingInstruction
- self._parser.CharacterDataHandler = self._cont_handler.characters
+ self._reset_cont_handler()
self._parser.UnparsedEntityDeclHandler = self.unparsed_entity_decl
self._parser.NotationDeclHandler = self.notation_decl
self._parser.StartNamespaceDeclHandler = self.start_namespace_decl
@@ -121,9 +145,7 @@ class ExpatParser(xmlreader.IncrementalParser, xmlreader.Locator):
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._reset_lex_handler_prop()
# self._parser.DefaultHandler =
# self._parser.DefaultHandlerExpand =
# self._parser.NotStandaloneHandler =