]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-38722: Runpy use io.open_code() (GH-17234)
authorjsnklln <jsnklln@gmail.com>
Mon, 18 Nov 2019 19:11:13 +0000 (14:11 -0500)
committerMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Mon, 18 Nov 2019 19:11:13 +0000 (11:11 -0800)
https://bugs.python.org/issue38722

Automerge-Triggered-By: @taleinat
Lib/runpy.py
Misc/NEWS.d/next/Security/2019-11-18-16-17-56.bpo-38722.x3mECW.rst [new file with mode: 0644]

index d86f0e4a3c49ba5443ba9b3206716b3462fe4de5..8adc91e32f319e734bc419d2a9299f767c4b9730 100644 (file)
@@ -13,6 +13,7 @@ importers when locating support scripts as well as when importing modules.
 import sys
 import importlib.machinery # importlib first so we can test #15386 via -m
 import importlib.util
+import io
 import types
 from pkgutil import read_code, get_importer
 
@@ -228,11 +229,11 @@ def _get_main_module_details(error=ImportError):
 
 def _get_code_from_file(run_name, fname):
     # Check for a compiled file first
-    with open(fname, "rb") as f:
+    with io.open_code(fname) as f:
         code = read_code(f)
     if code is None:
         # That didn't work, so try it as normal source code
-        with open(fname, "rb") as f:
+        with io.open_code(fname) as f:
             code = compile(f.read(), fname, 'exec')
     return code, fname
 
diff --git a/Misc/NEWS.d/next/Security/2019-11-18-16-17-56.bpo-38722.x3mECW.rst b/Misc/NEWS.d/next/Security/2019-11-18-16-17-56.bpo-38722.x3mECW.rst
new file mode 100644 (file)
index 0000000..0277d3e
--- /dev/null
@@ -0,0 +1,2 @@
+:mod:`runpy` now uses :meth:`io.open_code` to open code files.
+Patch by Jason Killen.