From 73e69e476f3e2fadd8e8d1fc3fa41f50f5d499ea Mon Sep 17 00:00:00 2001 From: Jason Killen Date: Fri, 15 Nov 2019 11:11:14 -0500 Subject: [PATCH 1/4] bpo-38722: runpy should use io.open_code() instead of open() This should be working but test.test_tools is failing when doing the full test. Switching branches to work on something else right now. --- Lib/runpy.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Lib/runpy.py b/Lib/runpy.py index d86f0e4a3c49ba5..8adc91e32f319e7 100644 --- a/Lib/runpy.py +++ b/Lib/runpy.py @@ -13,6 +13,7 @@ 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 From 38ffaa2a2a2635efe72732a55db6429cd53e5b61 Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" <43283697+blurb-it[bot]@users.noreply.github.com> Date: Mon, 18 Nov 2019 16:17:56 +0000 Subject: [PATCH 2/4] =?UTF-8?q?=F0=9F=93=9C=F0=9F=A4=96=20Added=20by=20blu?= =?UTF-8?q?rb=5Fit.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../next/Security/2019-11-18-16-17-56.bpo-38722.x3mECW.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Security/2019-11-18-16-17-56.bpo-38722.x3mECW.rst 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 index 000000000000000..7452d7569fb5e4a --- /dev/null +++ b/Misc/NEWS.d/next/Security/2019-11-18-16-17-56.bpo-38722.x3mECW.rst @@ -0,0 +1 @@ +:mod:`runpy` now uses :meth:`io.open_code` which will trigger auditing events. \ No newline at end of file From 535c459eb8da16a98ec52b02f9f6b30bbc359cbd Mon Sep 17 00:00:00 2001 From: Jason Killen Date: Mon, 18 Nov 2019 13:30:31 -0500 Subject: [PATCH 3/4] Better definition of what the change actually means. --- .../next/Security/2019-11-18-16-17-56.bpo-38722.x3mECW.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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 index 7452d7569fb5e4a..b452cddf1fbc22c 100644 --- 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 @@ -1 +1,2 @@ -:mod:`runpy` now uses :meth:`io.open_code` which will trigger auditing events. \ No newline at end of file +:mod:`runpy` now uses :meth:`io.open_code`. If a custom handler has been +set by :meth:`PyFile_SetOpenCodeHook` the custom handler will be called. From 32d33cfc1f307dc88f06f91c667e0349ba577ea5 Mon Sep 17 00:00:00 2001 From: Tal Einat Date: Mon, 18 Nov 2019 20:45:30 +0200 Subject: [PATCH 4/4] shorten NEWS entry --- .../next/Security/2019-11-18-16-17-56.bpo-38722.x3mECW.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 index b452cddf1fbc22c..0277d3e5689a2ab 100644 --- 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 @@ -1,2 +1,2 @@ -:mod:`runpy` now uses :meth:`io.open_code`. If a custom handler has been -set by :meth:`PyFile_SetOpenCodeHook` the custom handler will be called. +:mod:`runpy` now uses :meth:`io.open_code` to open code files. +Patch by Jason Killen.