Always close files in distutils code and tests (#10252).
diff --git a/Lib/distutils/command/bdist_wininst.py b/Lib/distutils/command/bdist_wininst.py
index 3aa1dac..b2e2fc6 100644
--- a/Lib/distutils/command/bdist_wininst.py
+++ b/Lib/distutils/command/bdist_wininst.py
@@ -340,4 +340,8 @@
sfix = ''
filename = os.path.join(directory, "wininst-%.1f%s.exe" % (bv, sfix))
- return open(filename, "rb").read()
+ f = open(filename, "rb")
+ try:
+ return f.read()
+ finally:
+ f.close()
diff --git a/Lib/distutils/command/upload.py b/Lib/distutils/command/upload.py
index 99e03d7..4926aa3 100644
--- a/Lib/distutils/command/upload.py
+++ b/Lib/distutils/command/upload.py
@@ -76,7 +76,11 @@
# Fill in the data - send all the meta-data in case we need to
# register a new release
- content = open(filename,'rb').read()
+ f = open(filename,'rb')
+ try:
+ content = f.read()
+ finally:
+ f.close()
meta = self.distribution.metadata
data = {
# action