Index: Lib/distutils/core.py =================================================================== --- Lib/distutils/core.py (revision 86124) +++ Lib/distutils/core.py (working copy) @@ -215,7 +215,11 @@ sys.argv[0] = script_name if script_args is not None: sys.argv[1:] = script_args - exec(open(script_name).read(), g, l) + f = open(script_name) + try: + exec(f.read(), g, l) + finally: + f.close() finally: sys.argv = save_argv _setup_stop_after = None Index: Lib/distutils/tests/test_register.py =================================================================== --- Lib/distutils/tests/test_register.py (revision 86124) +++ Lib/distutils/tests/test_register.py (working copy) @@ -118,8 +118,10 @@ self.assertTrue(os.path.exists(self.rc)) # with the content similar to WANTED_PYPIRC - content = open(self.rc).read() + f = open(self.rc) + content = f.read() self.assertEquals(content, WANTED_PYPIRC) + f.close() # now let's make sure the .pypirc file generated # really works : we shouldn't be asked anything Index: Lib/distutils/tests/test_core.py =================================================================== --- Lib/distutils/tests/test_core.py (revision 86124) +++ Lib/distutils/tests/test_core.py (working copy) @@ -52,7 +52,9 @@ shutil.rmtree(path) def write_setup(self, text, path=test.support.TESTFN): - open(path, "w").write(text) + f = open(path, "w") + f.write(text) + f.close() return path def test_run_setup_provides_file(self): Index: Lib/distutils/tests/test_config.py =================================================================== --- Lib/distutils/tests/test_config.py (revision 86124) +++ Lib/distutils/tests/test_config.py (working copy) @@ -105,8 +105,10 @@ self.assertTrue(not os.path.exists(rc)) cmd._store_pypirc('tarek', 'xxx') self.assertTrue(os.path.exists(rc)) - content = open(rc).read() + f = open(rc) + content = f.read() self.assertEquals(content, WANTED) + f.close() def test_suite(): return unittest.makeSuite(PyPIRCCommandTestCase) Index: Lib/distutils/tests/test_text_file.py =================================================================== --- Lib/distutils/tests/test_text_file.py (revision 86124) +++ Lib/distutils/tests/test_text_file.py (working copy) @@ -58,28 +58,34 @@ finally: out_file.close() - in_file = TextFile (filename, strip_comments=0, skip_blanks=0, - lstrip_ws=0, rstrip_ws=0) + in_file = TextFile(filename, strip_comments=0, skip_blanks=0, + lstrip_ws=0, rstrip_ws=0) test_input (1, "no processing", in_file, result1) + in_file.close() - in_file = TextFile (filename, strip_comments=1, skip_blanks=0, - lstrip_ws=0, rstrip_ws=0) + in_file = TextFile(filename, strip_comments=1, skip_blanks=0, + lstrip_ws=0, rstrip_ws=0) test_input (2, "strip comments", in_file, result2) + in_file.close() - in_file = TextFile (filename, strip_comments=0, skip_blanks=1, - lstrip_ws=0, rstrip_ws=0) + in_file = TextFile(filename, strip_comments=0, skip_blanks=1, + lstrip_ws=0, rstrip_ws=0) test_input (3, "strip blanks", in_file, result3) + in_file.close() - in_file = TextFile (filename) + in_file = TextFile(filename) test_input (4, "default processing", in_file, result4) + in_file.close() - in_file = TextFile (filename, strip_comments=1, skip_blanks=1, - join_lines=1, rstrip_ws=1) + in_file = TextFile(filename, strip_comments=1, skip_blanks=1, + join_lines=1, rstrip_ws=1) test_input (5, "join lines without collapsing", in_file, result5) + in_file.close() - in_file = TextFile (filename, strip_comments=1, skip_blanks=1, - join_lines=1, rstrip_ws=1, collapse_join=1) + in_file = TextFile(filename, strip_comments=1, skip_blanks=1, + join_lines=1, rstrip_ws=1, collapse_join=1) test_input (6, "join lines with collapsing", in_file, result6) + in_file.close() def test_suite(): return unittest.makeSuite(TextFileTestCase) Index: Lib/distutils/tests/test_sdist.py =================================================================== --- Lib/distutils/tests/test_sdist.py (revision 86124) +++ Lib/distutils/tests/test_sdist.py (working copy) @@ -215,8 +215,10 @@ self.assertEquals(len(content), 11) # checking the MANIFEST - manifest = open(join(self.tmp_dir, 'MANIFEST')).read() + f = open(join(self.tmp_dir, 'MANIFEST')) + manifest = f.read() self.assertEquals(manifest, MANIFEST % {'sep': os.sep}) + f.close() def test_metadata_check_option(self): # testing the `medata-check` option Index: Lib/distutils/command/bdist_wininst.py =================================================================== --- Lib/distutils/command/bdist_wininst.py (revision 86124) +++ Lib/distutils/command/bdist_wininst.py (working copy) @@ -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() Index: Lib/distutils/command/upload.py =================================================================== --- Lib/distutils/command/upload.py (revision 86124) +++ Lib/distutils/command/upload.py (working copy) @@ -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 Index: Lib/distutils/extension.py =================================================================== --- Lib/distutils/extension.py (revision 86124) +++ Lib/distutils/extension.py (working copy) @@ -149,84 +149,87 @@ file = TextFile(filename, strip_comments=1, skip_blanks=1, join_lines=1, lstrip_ws=1, rstrip_ws=1) - extensions = [] + try: + extensions = [] - while True: - line = file.readline() - if line is None: # eof - break - if _variable_rx.match(line): # VAR=VALUE, handled in first pass - continue + while True: + line = file.readline() + if line is None: # eof + break + if _variable_rx.match(line): # VAR=VALUE, handled in first pass + continue - if line[0] == line[-1] == "*": - file.warn("'%s' lines not handled yet" % line) - continue + if line[0] == line[-1] == "*": + file.warn("'%s' lines not handled yet" % line) + continue - line = expand_makefile_vars(line, vars) - words = split_quoted(line) + line = expand_makefile_vars(line, vars) + words = split_quoted(line) - # NB. this parses a slightly different syntax than the old - # makesetup script: here, there must be exactly one extension per - # line, and it must be the first word of the line. I have no idea - # why the old syntax supported multiple extensions per line, as - # they all wind up being the same. + # NB. this parses a slightly different syntax than the old + # makesetup script: here, there must be exactly one extension per + # line, and it must be the first word of the line. I have no idea + # why the old syntax supported multiple extensions per line, as + # they all wind up being the same. - module = words[0] - ext = Extension(module, []) - append_next_word = None + module = words[0] + ext = Extension(module, []) + append_next_word = None - for word in words[1:]: - if append_next_word is not None: - append_next_word.append(word) - append_next_word = None - continue + for word in words[1:]: + if append_next_word is not None: + append_next_word.append(word) + append_next_word = None + continue - suffix = os.path.splitext(word)[1] - switch = word[0:2] ; value = word[2:] + suffix = os.path.splitext(word)[1] + switch = word[0:2] ; value = word[2:] - if suffix in (".c", ".cc", ".cpp", ".cxx", ".c++", ".m", ".mm"): - # hmm, should we do something about C vs. C++ sources? - # or leave it up to the CCompiler implementation to - # worry about? - ext.sources.append(word) - elif switch == "-I": - ext.include_dirs.append(value) - elif switch == "-D": - equals = value.find("=") - if equals == -1: # bare "-DFOO" -- no value - ext.define_macros.append((value, None)) - else: # "-DFOO=blah" - ext.define_macros.append((value[0:equals], - value[equals+2:])) - elif switch == "-U": - ext.undef_macros.append(value) - elif switch == "-C": # only here 'cause makesetup has it! - ext.extra_compile_args.append(word) - elif switch == "-l": - ext.libraries.append(value) - elif switch == "-L": - ext.library_dirs.append(value) - elif switch == "-R": - ext.runtime_library_dirs.append(value) - elif word == "-rpath": - append_next_word = ext.runtime_library_dirs - elif word == "-Xlinker": - append_next_word = ext.extra_link_args - elif word == "-Xcompiler": - append_next_word = ext.extra_compile_args - elif switch == "-u": - ext.extra_link_args.append(word) - if not value: + if suffix in (".c", ".cc", ".cpp", ".cxx", ".c++", ".m", ".mm"): + # hmm, should we do something about C vs. C++ sources? + # or leave it up to the CCompiler implementation to + # worry about? + ext.sources.append(word) + elif switch == "-I": + ext.include_dirs.append(value) + elif switch == "-D": + equals = value.find("=") + if equals == -1: # bare "-DFOO" -- no value + ext.define_macros.append((value, None)) + else: # "-DFOO=blah" + ext.define_macros.append((value[0:equals], + value[equals+2:])) + elif switch == "-U": + ext.undef_macros.append(value) + elif switch == "-C": # only here 'cause makesetup has it! + ext.extra_compile_args.append(word) + elif switch == "-l": + ext.libraries.append(value) + elif switch == "-L": + ext.library_dirs.append(value) + elif switch == "-R": + ext.runtime_library_dirs.append(value) + elif word == "-rpath": + append_next_word = ext.runtime_library_dirs + elif word == "-Xlinker": append_next_word = ext.extra_link_args - elif suffix in (".a", ".so", ".sl", ".o", ".dylib"): - # NB. a really faithful emulation of makesetup would - # append a .o file to extra_objects only if it - # had a slash in it; otherwise, it would s/.o/.c/ - # and append it to sources. Hmmmm. - ext.extra_objects.append(word) - else: - file.warn("unrecognized argument '%s'" % word) + elif word == "-Xcompiler": + append_next_word = ext.extra_compile_args + elif switch == "-u": + ext.extra_link_args.append(word) + if not value: + append_next_word = ext.extra_link_args + elif suffix in (".a", ".so", ".sl", ".o", ".dylib"): + # NB. a really faithful emulation of makesetup would + # append a .o file to extra_objects only if it + # had a slash in it; otherwise, it would s/.o/.c/ + # and append it to sources. Hmmmm. + ext.extra_objects.append(word) + else: + file.warn("unrecognized argument '%s'" % word) - extensions.append(ext) + extensions.append(ext) + finally: + file.close() return extensions