diff options
author | Antoine Pitrou <solipsis@pitrou.net> | 2010-10-14 21:17:39 (GMT) |
---|---|---|
committer | Antoine Pitrou <solipsis@pitrou.net> | 2010-10-14 21:17:39 (GMT) |
commit | 3d400b7a58a9f6e338048593ae19ab3cc92a8cd3 (patch) | |
tree | 0eac5be6c10a5c55054461d68fe5f62a35713610 /Lib | |
parent | 51be0f47fa871a7b45c6407183110fde02a79997 (diff) | |
download | cpython-3d400b7a58a9f6e338048593ae19ab3cc92a8cd3.zip cpython-3d400b7a58a9f6e338048593ae19ab3cc92a8cd3.tar.gz cpython-3d400b7a58a9f6e338048593ae19ab3cc92a8cd3.tar.bz2 |
Merged revisions 85497 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/py3k
........
r85497 | antoine.pitrou | 2010-10-14 23:15:17 +0200 (jeu., 14 oct. 2010) | 3 lines
Explicitly close some files (from issue #10093)
........
Diffstat (limited to 'Lib')
-rwxr-xr-x | Lib/base64.py | 3 | ||||
-rw-r--r-- | Lib/mimetypes.py | 7 |
2 files changed, 5 insertions, 5 deletions
diff --git a/Lib/base64.py b/Lib/base64.py index b31c410..f93b3a4 100755 --- a/Lib/base64.py +++ b/Lib/base64.py @@ -383,7 +383,8 @@ def main(): if o == '-u': func = decode if o == '-t': test(); return if args and args[0] != '-': - func(open(args[0], 'rb'), sys.stdout.buffer) + with open(args[0], 'rb') as f: + func(f, sys.stdout.buffer) else: func(sys.stdin.buffer, sys.stdout.buffer) diff --git a/Lib/mimetypes.py b/Lib/mimetypes.py index f0da453..874037e 100644 --- a/Lib/mimetypes.py +++ b/Lib/mimetypes.py @@ -193,9 +193,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): """ @@ -302,7 +301,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] |