summaryrefslogtreecommitdiffstats
path: root/Lib/distutils/util.py
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2018-12-20 17:00:14 (GMT)
committerGitHub <noreply@github.com>2018-12-20 17:00:14 (GMT)
commitc5d5dfdb223efb0e668e3f317d31b8b70ae96aa6 (patch)
tree75d656ef90a71f12cdf8b9cdbbaeaf3b4c341156 /Lib/distutils/util.py
parent71f82a2f2085464f5ec99c16bce57bd1631733bd (diff)
downloadcpython-c5d5dfdb223efb0e668e3f317d31b8b70ae96aa6.zip
cpython-c5d5dfdb223efb0e668e3f317d31b8b70ae96aa6.tar.gz
cpython-c5d5dfdb223efb0e668e3f317d31b8b70ae96aa6.tar.bz2
bpo-22831: Use "with" to avoid possible fd leaks in distutils. (GH-10921)
Diffstat (limited to 'Lib/distutils/util.py')
-rw-r--r--Lib/distutils/util.py37
1 files changed, 18 insertions, 19 deletions
diff --git a/Lib/distutils/util.py b/Lib/distutils/util.py
index 30a21e4..15cd2ad 100644
--- a/Lib/distutils/util.py
+++ b/Lib/distutils/util.py
@@ -378,35 +378,34 @@ def byte_compile (py_files,
else:
script = open(script_name, "w")
- script.write("""\
+ with script:
+ script.write("""\
from distutils.util import byte_compile
files = [
""")
- # XXX would be nice to write absolute filenames, just for
- # safety's sake (script should be more robust in the face of
- # chdir'ing before running it). But this requires abspath'ing
- # 'prefix' as well, and that breaks the hack in build_lib's
- # 'byte_compile()' method that carefully tacks on a trailing
- # slash (os.sep really) to make sure the prefix here is "just
- # right". This whole prefix business is rather delicate -- the
- # problem is that it's really a directory, but I'm treating it
- # as a dumb string, so trailing slashes and so forth matter.
-
- #py_files = map(os.path.abspath, py_files)
- #if prefix:
- # prefix = os.path.abspath(prefix)
-
- script.write(",\n".join(map(repr, py_files)) + "]\n")
- script.write("""
+ # XXX would be nice to write absolute filenames, just for
+ # safety's sake (script should be more robust in the face of
+ # chdir'ing before running it). But this requires abspath'ing
+ # 'prefix' as well, and that breaks the hack in build_lib's
+ # 'byte_compile()' method that carefully tacks on a trailing
+ # slash (os.sep really) to make sure the prefix here is "just
+ # right". This whole prefix business is rather delicate -- the
+ # problem is that it's really a directory, but I'm treating it
+ # as a dumb string, so trailing slashes and so forth matter.
+
+ #py_files = map(os.path.abspath, py_files)
+ #if prefix:
+ # prefix = os.path.abspath(prefix)
+
+ script.write(",\n".join(map(repr, py_files)) + "]\n")
+ script.write("""
byte_compile(files, optimize=%r, force=%r,
prefix=%r, base_dir=%r,
verbose=%r, dry_run=0,
direct=1)
""" % (optimize, force, prefix, base_dir, verbose))
- script.close()
-
cmd = [sys.executable]
cmd.extend(subprocess._optim_args_from_interpreter_flags())
cmd.append(script_name)