mirror of
https://github.com/python/cpython.git
synced 2025-07-24 03:35:53 +00:00
Issue #20331: Fixed possible FD leaks in various modules:
http.server, imghdr, mailcap, mimetypes, xml.etree.
This commit is contained in:
commit
c0b0bb6e01
5 changed files with 34 additions and 30 deletions
|
@ -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
|
||||
|
||||
##
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue