bpo-22831: Use "with" to avoid possible fd leaks in tools (part 2). (GH-10927)
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 @@
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 @@
# 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) )