diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2014-01-25 17:43:56 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2014-01-25 17:43:56 (GMT) |
commit | c0b0bb6e01f7ea6a1a857609e794842223c4aa5c (patch) | |
tree | 23a00341a5a15f7af05ecd0549eb729dd906788a /Lib/xml | |
parent | a3642b67ca2656ec6d5c10a52bbb643462236ded (diff) | |
parent | 91b0bc237c07b52c771e121098989680cfc3600d (diff) | |
download | cpython-c0b0bb6e01f7ea6a1a857609e794842223c4aa5c.zip cpython-c0b0bb6e01f7ea6a1a857609e794842223c4aa5c.tar.gz cpython-c0b0bb6e01f7ea6a1a857609e794842223c4aa5c.tar.bz2 |
Issue #20331: Fixed possible FD leaks in various modules:
http.server, imghdr, mailcap, mimetypes, xml.etree.
Diffstat (limited to 'Lib/xml')
-rw-r--r-- | Lib/xml/etree/ElementInclude.py | 9 |
1 files changed, 4 insertions, 5 deletions
diff --git a/Lib/xml/etree/ElementInclude.py b/Lib/xml/etree/ElementInclude.py index 73e491e..963470e 100644 --- a/Lib/xml/etree/ElementInclude.py +++ b/Lib/xml/etree/ElementInclude.py @@ -76,14 +76,13 @@ class FatalIncludeError(SyntaxError): def default_loader(href, parse, encoding=None): if parse == "xml": - file = open(href, 'rb') - data = ElementTree.parse(file).getroot() + with open(href, 'rb') as file: + data = ElementTree.parse(file).getroot() else: if not encoding: encoding = 'UTF-8' - file = open(href, 'r', encoding=encoding) - data = file.read() - file.close() + with open(href, 'r', encoding=encoding) as file: + data = file.read() return data ## |