diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2014-01-25 17:42:27 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2014-01-25 17:42:27 (GMT) |
commit | 1adbacfd1c80f4f724c5d515e48a518d0b1be2dd (patch) | |
tree | c2c0e80d7163597cd158aaad1626720b418b1fda /Lib/xml | |
parent | d8be9feb45baab60959d4076dc997062b307206f (diff) | |
download | cpython-1adbacfd1c80f4f724c5d515e48a518d0b1be2dd.zip cpython-1adbacfd1c80f4f724c5d515e48a518d0b1be2dd.tar.gz cpython-1adbacfd1c80f4f724c5d515e48a518d0b1be2dd.tar.bz2 |
Issue #20331: Fixed possible FD leaks in various modules:
SimpleHTTPServer, imghdr, mailcap, mimetypes, xml.etree.
Diffstat (limited to 'Lib/xml')
-rw-r--r-- | Lib/xml/etree/ElementInclude.py | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/Lib/xml/etree/ElementInclude.py b/Lib/xml/etree/ElementInclude.py index 84fd754..7e29119 100644 --- a/Lib/xml/etree/ElementInclude.py +++ b/Lib/xml/etree/ElementInclude.py @@ -75,14 +75,13 @@ class FatalIncludeError(SyntaxError): # @throws IOError If the loader fails to load the resource. def default_loader(href, parse, encoding=None): - file = open(href) - if parse == "xml": - data = ElementTree.parse(file).getroot() - else: - data = file.read() - if encoding: - data = data.decode(encoding) - file.close() + with open(href) as file: + if parse == "xml": + data = ElementTree.parse(file).getroot() + else: + data = file.read() + if encoding: + data = data.decode(encoding) return data ## |