Index: Lib/distutils/command/bdist_wininst.py =================================================================== --- Lib/distutils/command/bdist_wininst.py (révision 88667) +++ Lib/distutils/command/bdist_wininst.py (copie de travail) @@ -245,7 +245,11 @@ self.announce("creating %s" % installer_name) if bitmap: - bitmapdata = open(bitmap, "rb").read() + fp = open(bitmap, "rb") + try: + bitmapdata = fp.read() + finally: + fp.close() bitmaplen = len(bitmapdata) else: bitmaplen = 0 Index: Lib/distutils/command/bdist_rpm.py =================================================================== --- Lib/distutils/command/bdist_rpm.py (révision 88667) +++ Lib/distutils/command/bdist_rpm.py (copie de travail) @@ -511,7 +511,12 @@ '', '%' + rpm_opt,]) if val: - spec_file.extend(open(val, 'r').read().split('\n')) + fp = open(val) + try: + contents = fp.read().split('\n') + finally: + fp.close() + spec_file.extend(contents) else: spec_file.append(default) Index: Lib/distutils/command/upload.py =================================================================== --- Lib/distutils/command/upload.py (révision 88667) +++ Lib/distutils/command/upload.py (copie de travail) @@ -124,8 +124,13 @@ data['comment'] = comment if self.sign: + fp = open(filename + '.asc') + try: + contents = fp.read() + finally: + fp.close() data['gpg_signature'] = (os.path.basename(filename) + ".asc", - open(filename+".asc").read()) + contents) # set up the authentication user_pass = (self.username + ":" + self.password).encode('ascii') Index: Lib/distutils/command/sdist.py =================================================================== --- Lib/distutils/command/sdist.py (révision 88667) +++ Lib/distutils/command/sdist.py (copie de travail) @@ -294,17 +294,20 @@ join_lines=1, lstrip_ws=1, rstrip_ws=1, collapse_join=1) - while True: - line = template.readline() - if line is None: # end of file - break + try: + while True: + line = template.readline() + if line is None: # end of file + break - try: - self.filelist.process_template_line(line) - except DistutilsTemplateError as msg: - self.warn("%s, line %d: %s" % (template.filename, - template.current_line, - msg)) + try: + self.filelist.process_template_line(line) + except DistutilsTemplateError as msg: + self.warn("%s, line %d: %s" % (template.filename, + template.current_line, + msg)) + finally: + template.close() def prune_file_list(self): """Prune off branches that might slip into the file list as created @@ -359,14 +362,16 @@ """ log.info("reading manifest file '%s'", self.manifest) manifest = open(self.manifest) - while True: - line = manifest.readline() - if line == '': # end of file - break - if line[-1] == '\n': - line = line[0:-1] - self.filelist.append(line) - manifest.close() + try: + while True: + line = manifest.readline() + if line == '': # end of file + break + if line[-1] == '\n': + line = line[0:-1] + self.filelist.append(line) + finally: + manifest.close() def make_release_tree(self, base_dir, files): """Create the directory tree that will become the source Index: Lib/distutils/sysconfig.py =================================================================== --- Lib/distutils/sysconfig.py (révision 88667) +++ Lib/distutils/sysconfig.py (copie de travail) @@ -270,91 +270,93 @@ from distutils.text_file import TextFile fp = TextFile(fn, strip_comments=1, skip_blanks=1, join_lines=1, errors="surrogateescape") - if g is None: - g = {} - done = {} - notdone = {} + try: + if g is None: + g = {} + done = {} + notdone = {} - while True: - line = fp.readline() - if line is None: # eof - break - m = _variable_rx.match(line) - if m: - n, v = m.group(1, 2) - v = v.strip() - # `$$' is a literal `$' in make - tmpv = v.replace('$$', '') + while True: + line = fp.readline() + if line is None: # eof + break + m = _variable_rx.match(line) + if m: + n, v = m.group(1, 2) + v = v.strip() + # `$$' is a literal `$' in make + tmpv = v.replace('$$', '') - if "$" in tmpv: - notdone[n] = v - else: - try: - v = int(v) - except ValueError: - # insert literal `$' - done[n] = v.replace('$$', '$') + if "$" in tmpv: + notdone[n] = v else: - done[n] = v + try: + v = int(v) + except ValueError: + # insert literal `$' + done[n] = v.replace('$$', '$') + else: + done[n] = v - # Variables with a 'PY_' prefix in the makefile. These need to - # be made available without that prefix through sysconfig. - # Special care is needed to ensure that variable expansion works, even - # if the expansion uses the name without a prefix. - renamed_variables = ('CFLAGS', 'LDFLAGS', 'CPPFLAGS') + # Variables with a 'PY_' prefix in the makefile. These need to + # be made available without that prefix through sysconfig. + # Special care is needed to ensure that variable expansion works, even + # if the expansion uses the name without a prefix. + renamed_variables = ('CFLAGS', 'LDFLAGS', 'CPPFLAGS') - # do variable interpolation here - while notdone: - for name in list(notdone): - value = notdone[name] - m = _findvar1_rx.search(value) or _findvar2_rx.search(value) - if m: - n = m.group(1) - found = True - if n in done: - item = str(done[n]) - elif n in notdone: - # get it on a subsequent round - found = False - elif n in os.environ: - # do it like make: fall back to environment - item = os.environ[n] + # do variable interpolation here + while notdone: + for name in list(notdone): + value = notdone[name] + m = _findvar1_rx.search(value) or _findvar2_rx.search(value) + if m: + n = m.group(1) + found = True + if n in done: + item = str(done[n]) + elif n in notdone: + # get it on a subsequent round + found = False + elif n in os.environ: + # do it like make: fall back to environment + item = os.environ[n] - elif n in renamed_variables: - if name.startswith('PY_') and name[3:] in renamed_variables: - item = "" + elif n in renamed_variables: + if name.startswith('PY_') and name[3:] in renamed_variables: + item = "" - elif 'PY_' + n in notdone: - found = False + elif 'PY_' + n in notdone: + found = False + else: + item = str(done['PY_' + n]) else: - item = str(done['PY_' + n]) - else: - done[n] = item = "" - if found: - after = value[m.end():] - value = value[:m.start()] + item + after - if "$" in after: - notdone[name] = value - else: - try: value = int(value) - except ValueError: - done[name] = value.strip() + done[n] = item = "" + if found: + after = value[m.end():] + value = value[:m.start()] + item + after + if "$" in after: + notdone[name] = value else: - done[name] = value - del notdone[name] + try: value = int(value) + except ValueError: + done[name] = value.strip() + else: + done[name] = value + del notdone[name] - if name.startswith('PY_') \ - and name[3:] in renamed_variables: + if name.startswith('PY_') \ + and name[3:] in renamed_variables: - name = name[3:] - if name not in done: - done[name] = value - else: - # bogus variable reference; just drop it since we can't deal - del notdone[name] + name = name[3:] + if name not in done: + done[name] = value + else: + # bogus variable reference; just drop it since we can't deal + del notdone[name] - fp.close() + finally: + fp.close() # strip spurious spaces for k, v in done.items():