summaryrefslogtreecommitdiffstats
path: root/Lib/xml
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2015-04-10 10:24:41 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2015-04-10 10:24:41 (GMT)
commit7e7a3dba5fd4262269f713dfe21ba7e4746fc2dd (patch)
treea0777a3e70ae76f294fac756c684ec4e24d5df1d /Lib/xml
parent842f00e72509db50957ceb00d289b305dbc5a0a5 (diff)
downloadcpython-7e7a3dba5fd4262269f713dfe21ba7e4746fc2dd.zip
cpython-7e7a3dba5fd4262269f713dfe21ba7e4746fc2dd.tar.gz
cpython-7e7a3dba5fd4262269f713dfe21ba7e4746fc2dd.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')
-rw-r--r--Lib/xml/sax/expatreader.py20
1 files changed, 11 insertions, 9 deletions
diff --git a/Lib/xml/sax/expatreader.py b/Lib/xml/sax/expatreader.py
index a227cda..29d75ab 100644
--- a/Lib/xml/sax/expatreader.py
+++ b/Lib/xml/sax/expatreader.py
@@ -211,17 +211,19 @@ 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
- bs = self._source.getByteStream()
- if bs is not None:
- bs.close()
+ 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
+ bs = self._source.getByteStream()
+ if bs is not None:
+ bs.close()
def _reset_cont_handler(self):
self._parser.ProcessingInstructionHandler = \