diff options
author | Éric Araujo <merwok@netwok.org> | 2010-11-06 02:58:56 (GMT) |
---|---|---|
committer | Éric Araujo <merwok@netwok.org> | 2010-11-06 02:58:56 (GMT) |
commit | c6d7ead095fdd3b1ee82a338d4ffd88b2c2c2fce (patch) | |
tree | 87bd3d5006d1f4050f64a44c59910461747f08dc /Lib/distutils/command | |
parent | 997980fe13ae7952665da56b122aeff9ea8fa6df (diff) | |
download | cpython-c6d7ead095fdd3b1ee82a338d4ffd88b2c2c2fce.zip cpython-c6d7ead095fdd3b1ee82a338d4ffd88b2c2c2fce.tar.gz cpython-c6d7ead095fdd3b1ee82a338d4ffd88b2c2c2fce.tar.bz2 |
Merged revisions 86223-86224,86226,86234 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/py3k
........
r86223 | eric.araujo | 2010-11-06 00:51:56 +0100 (sam., 06 nov. 2010) | 2 lines
Always close files in distutils code and tests (#10252).
........
r86224 | eric.araujo | 2010-11-06 00:58:34 +0100 (sam., 06 nov. 2010) | 2 lines
Add missing entry for r86223.
........
r86226 | eric.araujo | 2010-11-06 00:59:32 +0100 (sam., 06 nov. 2010) | 2 lines
Of course, I forgot one file in r86223.
........
r86234 | eric.araujo | 2010-11-06 03:10:32 +0100 (sam., 06 nov. 2010) | 2 lines
Also close file descriptors from os.popen and subprocess.Popen
........
Diffstat (limited to 'Lib/distutils/command')
-rw-r--r-- | Lib/distutils/command/bdist_rpm.py | 36 | ||||
-rw-r--r-- | Lib/distutils/command/bdist_wininst.py | 6 | ||||
-rw-r--r-- | Lib/distutils/command/upload.py | 6 |
3 files changed, 30 insertions, 18 deletions
diff --git a/Lib/distutils/command/bdist_rpm.py b/Lib/distutils/command/bdist_rpm.py index 452f950..e2ae877 100644 --- a/Lib/distutils/command/bdist_rpm.py +++ b/Lib/distutils/command/bdist_rpm.py @@ -343,22 +343,26 @@ class bdist_rpm(Command): src_rpm, non_src_rpm, spec_path) out = os.popen(q_cmd) - binary_rpms = [] - source_rpm = None - while True: - line = out.readline() - if not line: - break - l = line.strip().split() - assert(len(l) == 2) - binary_rpms.append(l[1]) - # The source rpm is named after the first entry in the spec file - if source_rpm is None: - source_rpm = l[0] - - status = out.close() - if status: - raise DistutilsExecError("Failed to execute: %s" % repr(q_cmd)) + try: + binary_rpms = [] + source_rpm = None + while True: + line = out.readline() + if not line: + break + l = line.strip().split() + assert(len(l) == 2) + binary_rpms.append(l[1]) + # The source rpm is named after the first entry in the spec file + if source_rpm is None: + source_rpm = l[0] + + status = out.close() + if status: + raise DistutilsExecError("Failed to execute: %s" % repr(q_cmd)) + + finally: + out.close() self.spawn(rpm_cmd) 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 @@ class bdist_wininst(Command): 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 @@ class upload(PyPIRCCommand): # 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 |