diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2015-04-10 10:24:10 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2015-04-10 10:24:10 (GMT) |
commit | 1aa2c0f073bdbed4fa824591d53e20bbf3d01add (patch) | |
tree | 30091bc4164edcf2d192126e5db59392a3078793 /Lib/xml/sax/expatreader.py | |
parent | c26afcc8fce54b8c920c21e2faf1259a92f4aa1f (diff) | |
download | cpython-1aa2c0f073bdbed4fa824591d53e20bbf3d01add.zip cpython-1aa2c0f073bdbed4fa824591d53e20bbf3d01add.tar.gz cpython-1aa2c0f073bdbed4fa824591d53e20bbf3d01add.tar.bz2 |
Issue #23865: close() methods in multiple modules now are idempotent and more
robust at shutdown. If needs to release multiple resources, they are released
even if errors are occured.
Diffstat (limited to 'Lib/xml/sax/expatreader.py')
-rw-r--r-- | Lib/xml/sax/expatreader.py | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/Lib/xml/sax/expatreader.py b/Lib/xml/sax/expatreader.py index 9de3e72..cd243e6 100644 --- a/Lib/xml/sax/expatreader.py +++ b/Lib/xml/sax/expatreader.py @@ -214,14 +214,16 @@ class ExpatParser(xmlreader.IncrementalParser, xmlreader.Locator): self._err_handler.fatalError(exc) def close(self): - if self._entity_stack: + if self._entity_stack or self._parser is None: # If we are completing an external entity, do nothing here return - self.feed("", isFinal = 1) - self._cont_handler.endDocument() - self._parsing = 0 - # break cycle created by expat handlers pointing to our methods - self._parser = None + 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 def _reset_cont_handler(self): self._parser.ProcessingInstructionHandler = \ |