mirror of
https://github.com/python/cpython.git
synced 2025-08-04 17:08:35 +00:00
Issue #24125: Saved error's line and column numbers when an error is occured
during closing expatreader. Fixed a regression introduced in issue #23865.
This commit is contained in:
commit
9749b5a6a3
2 changed files with 15 additions and 2 deletions
|
@ -43,6 +43,9 @@ else:
|
|||
_mkproxy = weakref.proxy
|
||||
del weakref, _weakref
|
||||
|
||||
class _ClosedParser:
|
||||
pass
|
||||
|
||||
# --- ExpatLocator
|
||||
|
||||
class ExpatLocator(xmlreader.Locator):
|
||||
|
@ -211,16 +214,24 @@ class ExpatParser(xmlreader.IncrementalParser, xmlreader.Locator):
|
|||
self._err_handler.fatalError(exc)
|
||||
|
||||
def close(self):
|
||||
if self._entity_stack or self._parser is None:
|
||||
if (self._entity_stack or self._parser is None or
|
||||
isinstance(self._parser, _ClosedParser)):
|
||||
# If we are completing an external entity, do nothing here
|
||||
return
|
||||
try:
|
||||
self.feed("", isFinal = 1)
|
||||
self._cont_handler.endDocument()
|
||||
finally:
|
||||
self._parsing = 0
|
||||
# break cycle created by expat handlers pointing to our methods
|
||||
self._parser = None
|
||||
finally:
|
||||
self._parsing = 0
|
||||
if self._parser is not None:
|
||||
# Keep ErrorColumnNumber and ErrorLineNumber after closing.
|
||||
parser = _ClosedParser()
|
||||
parser.ErrorColumnNumber = self._parser.ErrorColumnNumber
|
||||
parser.ErrorLineNumber = self._parser.ErrorLineNumber
|
||||
self._parser = parser
|
||||
try:
|
||||
file = self._source.getCharacterStream()
|
||||
if file is not None:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue