summaryrefslogtreecommitdiffstats
path: root/Lib/xml
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2014-01-25 17:42:27 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2014-01-25 17:42:27 (GMT)
commit1adbacfd1c80f4f724c5d515e48a518d0b1be2dd (patch)
treec2c0e80d7163597cd158aaad1626720b418b1fda /Lib/xml
parentd8be9feb45baab60959d4076dc997062b307206f (diff)
downloadcpython-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.py15
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
##