diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2019-03-30 06:33:02 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-03-30 06:33:02 (GMT) |
commit | 172bb39452ae8b3ccdf5d1f23ead46f44200cd49 (patch) | |
tree | 5e1effbca3664b839a81eb7a7d62fa4974cfbfb1 /Tools/freeze | |
parent | afbb7a371fb44edc731344eab5b474ad8f7b57d7 (diff) | |
download | cpython-172bb39452ae8b3ccdf5d1f23ead46f44200cd49.zip cpython-172bb39452ae8b3ccdf5d1f23ead46f44200cd49.tar.gz cpython-172bb39452ae8b3ccdf5d1f23ead46f44200cd49.tar.bz2 |
bpo-22831: Use "with" to avoid possible fd leaks in tools (part 2). (GH-10927)
Diffstat (limited to 'Tools/freeze')
-rw-r--r-- | Tools/freeze/checkextensions_win32.py | 3 | ||||
-rwxr-xr-x | Tools/freeze/freeze.py | 3 |
2 files changed, 4 insertions, 2 deletions
diff --git a/Tools/freeze/checkextensions_win32.py b/Tools/freeze/checkextensions_win32.py index c9cb576..64350df 100644 --- a/Tools/freeze/checkextensions_win32.py +++ b/Tools/freeze/checkextensions_win32.py @@ -130,7 +130,8 @@ def parse_dsp(dsp): ret = [] dsp_path, dsp_name = os.path.split(dsp) try: - lines = open(dsp, "r").readlines() + with open(dsp, "r") as fp: + lines = fp.readlines() except IOError as msg: sys.stderr.write("%s: %s\n" % (dsp, msg)) return None diff --git a/Tools/freeze/freeze.py b/Tools/freeze/freeze.py index 3ab56fd..83aa508 100755 --- a/Tools/freeze/freeze.py +++ b/Tools/freeze/freeze.py @@ -142,7 +142,8 @@ def main(): # last option can not be "-i", so this ensures "pos+1" is in range! if sys.argv[pos] == '-i': try: - options = open(sys.argv[pos+1]).read().split() + with open(sys.argv[pos+1]) as infp: + options = infp.read().split() except IOError as why: usage("File name '%s' specified with the -i option " "can not be read - %s" % (sys.argv[pos+1], why) ) |