Explicitly close some files (from issue #10093)

This commit is contained in:
Antoine Pitrou 2010-10-14 21:15:17 +00:00
parent d9f57630fe
commit b86680e299
6 changed files with 31 additions and 14 deletions

View file

@ -199,9 +199,8 @@ class MimeTypes:
list of standard types, else to the list of non-standard
types.
"""
fp = open(filename)
self.readfp(fp, strict)
fp.close()
with open(filename) as fp:
self.readfp(fp, strict)
def readfp(self, fp, strict=True):
"""
@ -348,7 +347,7 @@ def init(files=None):
files = knownfiles
for file in files:
if os.path.isfile(file):
db.readfp(open(file))
db.read(file)
encodings_map = db.encodings_map
suffix_map = db.suffix_map
types_map = db.types_map[True]