summaryrefslogtreecommitdiffstats
path: root/Lib/xml/etree
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2014-01-25 17:43:02 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2014-01-25 17:43:02 (GMT)
commit91b0bc237c07b52c771e121098989680cfc3600d (patch)
tree96ce4b2c32292bf2f619846c1599c9af0142f2f7 /Lib/xml/etree
parent933209689e8d07e3ce00c68ca26e001b130f0b62 (diff)
downloadcpython-91b0bc237c07b52c771e121098989680cfc3600d.zip
cpython-91b0bc237c07b52c771e121098989680cfc3600d.tar.gz
cpython-91b0bc237c07b52c771e121098989680cfc3600d.tar.bz2
Issue #20331: Fixed possible FD leaks in various modules:
http.server, imghdr, mailcap, mimetypes, xml.etree.
Diffstat (limited to 'Lib/xml/etree')
-rw-r--r--Lib/xml/etree/ElementInclude.py9
1 files changed, 4 insertions, 5 deletions
diff --git a/Lib/xml/etree/ElementInclude.py b/Lib/xml/etree/ElementInclude.py
index 6cc1b44..71eeb05 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
##