(original) (raw)
changeset: 95892:7f8cd879687b branch: 3.4 parent: 95884:29512e2015d9 user: Serhiy Storchaka storchaka@gmail.com date: Wed May 06 09:36:06 2015 +0300 files: Lib/test/test_sax.py Lib/xml/sax/expatreader.py description: Issue #24125: Saved error's line and column numbers when an error is occured during closing expatreader. Fixed a regression introduced in issue #23865. diff -r 29512e2015d9 -r 7f8cd879687b Lib/test/test_sax.py --- a/Lib/test/test_sax.py Wed May 06 01:13:02 2015 +0200 +++ b/Lib/test/test_sax.py Wed May 06 09:36:06 2015 +0300 @@ -1126,6 +1126,8 @@ parser = create_parser() parser.setContentHandler(ContentHandler()) # do nothing self.assertRaises(SAXParseException, parser.parse, StringIO("")) + 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 -r 29512e2015d9 -r 7f8cd879687b Lib/xml/sax/expatreader.py --- a/Lib/xml/sax/expatreader.py Wed May 06 01:13:02 2015 +0200 +++ b/Lib/xml/sax/expatreader.py Wed May 06 09:36:06 2015 +0300 @@ -43,6 +43,9 @@ _mkproxy = weakref.proxy del weakref, _weakref +class _ClosedParser: + pass + # --- ExpatLocator class ExpatLocator(xmlreader.Locator): @@ -211,16 +214,24 @@ 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()/storchaka@gmail.com