diff options
author | Steve Dower <steve.dower@python.org> | 2023-04-27 21:44:07 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-04-27 21:44:07 (GMT) |
commit | e277266a926a9037d39f1af7751050012f7f1998 (patch) | |
tree | a40c16f5a2b04a5a66918c9ddcc56882d107142c /Lib | |
parent | 4075e0166fcae0eef5e3abe1a97b3c227ce6861c (diff) | |
download | cpython-e277266a926a9037d39f1af7751050012f7f1998.zip cpython-e277266a926a9037d39f1af7751050012f7f1998.tar.gz cpython-e277266a926a9037d39f1af7751050012f7f1998.tar.bz2 |
gh-103935: Use `io.open_code()` when executing code in trace and profile modules (GH-103947)
Co-authored-by: Tian Gao <gaogaotiantian@hotmail.com>
Diffstat (limited to 'Lib')
-rwxr-xr-x | Lib/cProfile.py | 3 | ||||
-rwxr-xr-x | Lib/profile.py | 3 | ||||
-rwxr-xr-x | Lib/trace.py | 3 |
3 files changed, 6 insertions, 3 deletions
diff --git a/Lib/cProfile.py b/Lib/cProfile.py index 22a7d0a..9ae1fb8 100755 --- a/Lib/cProfile.py +++ b/Lib/cProfile.py @@ -7,6 +7,7 @@ __all__ = ["run", "runctx", "Profile"] import _lsprof +import io import profile as _pyprofile # ____________________________________________________________ @@ -167,7 +168,7 @@ def main(): else: progname = args[0] sys.path.insert(0, os.path.dirname(progname)) - with open(progname, 'rb') as fp: + with io.open_code(progname) as fp: code = compile(fp.read(), progname, 'exec') globs = { '__file__': progname, diff --git a/Lib/profile.py b/Lib/profile.py index d8599fb..90c4e4c 100755 --- a/Lib/profile.py +++ b/Lib/profile.py @@ -24,6 +24,7 @@ # governing permissions and limitations under the License. +import io import sys import time import marshal @@ -587,7 +588,7 @@ def main(): else: progname = args[0] sys.path.insert(0, os.path.dirname(progname)) - with open(progname, 'rb') as fp: + with io.open_code(progname) as fp: code = compile(fp.read(), progname, 'exec') globs = { '__file__': progname, diff --git a/Lib/trace.py b/Lib/trace.py index 213e465..fb9a423 100755 --- a/Lib/trace.py +++ b/Lib/trace.py @@ -49,6 +49,7 @@ Sample use, programmatically """ __all__ = ['Trace', 'CoverageResults'] +import io import linecache import os import sys @@ -716,7 +717,7 @@ def main(): sys.argv = [opts.progname, *opts.arguments] sys.path[0] = os.path.dirname(opts.progname) - with open(opts.progname, 'rb') as fp: + with io.open_code(opts.progname) as fp: code = compile(fp.read(), opts.progname, 'exec') # try to emulate __main__ namespace as much as possible globs = { |