Synchronize with PyXML 1.10
Break cycle involving expat parser in close(). Add lex handler support to SAX2 pyexpat
This commit is contained in:
parent
52ce0d0837
commit
0591725bc5
|
@ -27,6 +27,7 @@ class ExpatParser(xmlreader.IncrementalParser, xmlreader.Locator):
|
|||
self._source = xmlreader.InputSource()
|
||||
self._parser = None
|
||||
self._namespaces = namespaceHandling
|
||||
self._lex_handler_prop = None
|
||||
self._parsing = 0
|
||||
self._entity_stack = []
|
||||
|
||||
|
@ -60,10 +61,15 @@ class ExpatParser(xmlreader.IncrementalParser, xmlreader.Locator):
|
|||
name)
|
||||
|
||||
def getProperty(self, name):
|
||||
if name == handler.property_lexical_handler:
|
||||
return self._lex_handler_prop
|
||||
raise SAXNotRecognizedException("Property '%s' not recognized" % name)
|
||||
|
||||
def setProperty(self, name, value):
|
||||
raise SAXNotRecognizedException("Property '%s' not recognized" % name)
|
||||
if name == handler.property_lexical_handler:
|
||||
self._lex_handler_prop = value
|
||||
else:
|
||||
raise SAXNotRecognizedException("Property '%s' not recognized" % name)
|
||||
|
||||
# IncrementalParser methods
|
||||
|
||||
|
@ -82,6 +88,7 @@ class ExpatParser(xmlreader.IncrementalParser, xmlreader.Locator):
|
|||
except expat.error:
|
||||
error_code = self._parser.ErrorCode
|
||||
exc = SAXParseException(expat.ErrorString(error_code), None, self)
|
||||
# FIXME: when to invoke error()?
|
||||
self._err_handler.fatalError(exc)
|
||||
|
||||
def close(self):
|
||||
|
@ -91,6 +98,8 @@ class ExpatParser(xmlreader.IncrementalParser, xmlreader.Locator):
|
|||
self.feed("", isFinal = 1)
|
||||
self._cont_handler.endDocument()
|
||||
self._parsing = 0
|
||||
# break cycle created by expat handlers pointing to our methods
|
||||
self._parser = None
|
||||
|
||||
def reset(self):
|
||||
if self._namespaces:
|
||||
|
@ -109,12 +118,15 @@ class ExpatParser(xmlreader.IncrementalParser, xmlreader.Locator):
|
|||
self._parser.NotationDeclHandler = self.notation_decl
|
||||
self._parser.StartNamespaceDeclHandler = self.start_namespace_decl
|
||||
self._parser.EndNamespaceDeclHandler = self.end_namespace_decl
|
||||
# self._parser.CommentHandler =
|
||||
# self._parser.StartCdataSectionHandler =
|
||||
# self._parser.EndCdataSectionHandler =
|
||||
# self._parser.DefaultHandler =
|
||||
# self._parser.DefaultHandlerExpand =
|
||||
# self._parser.NotStandaloneHandler =
|
||||
|
||||
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 =
|
||||
# self._parser.NotStandaloneHandler =
|
||||
self._parser.ExternalEntityRefHandler = self.external_entity_ref
|
||||
|
||||
self._parsing = 0
|
||||
|
@ -123,9 +135,13 @@ class ExpatParser(xmlreader.IncrementalParser, xmlreader.Locator):
|
|||
# Locator methods
|
||||
|
||||
def getColumnNumber(self):
|
||||
if self._parser is None:
|
||||
return None
|
||||
return self._parser.ErrorColumnNumber
|
||||
|
||||
def getLineNumber(self):
|
||||
if self._parser is None:
|
||||
return 1
|
||||
return self._parser.ErrorLineNumber
|
||||
|
||||
def getPublicId(self):
|
||||
|
@ -165,6 +181,8 @@ class ExpatParser(xmlreader.IncrementalParser, xmlreader.Locator):
|
|||
pair = string.split(name)
|
||||
if len(pair) == 1:
|
||||
pair = (None, name)
|
||||
else:
|
||||
pair = tuple(pair)
|
||||
|
||||
self._cont_handler.endElementNS(pair, None)
|
||||
|
||||
|
|
Loading…
Reference in New Issue