diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2015-05-06 06:36:06 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2015-05-06 06:36:06 (GMT) |
commit | ab914780ba6165620e3db81d11cb631de58b655a (patch) | |
tree | e914f6cde1837f1f5586f82af566f944191d7539 /Lib | |
parent | e8042e5e98a8a368f7d067683269c7cd0f663dfd (diff) | |
download | cpython-ab914780ba6165620e3db81d11cb631de58b655a.zip cpython-ab914780ba6165620e3db81d11cb631de58b655a.tar.gz cpython-ab914780ba6165620e3db81d11cb631de58b655a.tar.bz2 |
Issue #24125: Saved error's line and column numbers when an error is occured
during closing expatreader. Fixed a regression introduced in issue #23865.
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_sax.py | 2 | ||||
-rw-r--r-- | Lib/xml/sax/expatreader.py | 15 |
2 files changed, 15 insertions, 2 deletions
diff --git a/Lib/test/test_sax.py b/Lib/test/test_sax.py index eabbf57..90f3016 100644 --- a/Lib/test/test_sax.py +++ b/Lib/test/test_sax.py @@ -1126,6 +1126,8 @@ class ErrorReportingTest(unittest.TestCase): parser = create_parser() parser.setContentHandler(ContentHandler()) # do nothing self.assertRaises(SAXParseException, parser.parse, StringIO("<foo>")) + self.assertEqual(parser.getColumnNumber(), 5) + self.assertEqual(parser.getLineNumber(), 1) def test_sax_parse_exception_str(self): # pass various values from a locator to the SAXParseException to diff --git a/Lib/xml/sax/expatreader.py b/Lib/xml/sax/expatreader.py index 29d75ab..3b63737 100644 --- a/Lib/xml/sax/expatreader.py +++ b/Lib/xml/sax/expatreader.py @@ -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 bs = self._source.getByteStream() if bs is not None: bs.close() |