mirror of https://github.com/python/cpython.git
gh-103935: Use `io.open_code()` when executing code in trace and profile modules (GH-103947)
This commit is contained in:
parent
bf0b8a9f8d
commit
d50f01ad0a
|
@ -8,6 +8,7 @@
|
||||||
|
|
||||||
import _lsprof
|
import _lsprof
|
||||||
import importlib.machinery
|
import importlib.machinery
|
||||||
|
import io
|
||||||
import profile as _pyprofile
|
import profile as _pyprofile
|
||||||
|
|
||||||
# ____________________________________________________________
|
# ____________________________________________________________
|
||||||
|
@ -168,7 +169,7 @@ def main():
|
||||||
else:
|
else:
|
||||||
progname = args[0]
|
progname = args[0]
|
||||||
sys.path.insert(0, os.path.dirname(progname))
|
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')
|
code = compile(fp.read(), progname, 'exec')
|
||||||
spec = importlib.machinery.ModuleSpec(name='__main__', loader=None,
|
spec = importlib.machinery.ModuleSpec(name='__main__', loader=None,
|
||||||
origin=progname)
|
origin=progname)
|
||||||
|
|
|
@ -25,6 +25,7 @@
|
||||||
|
|
||||||
|
|
||||||
import importlib.machinery
|
import importlib.machinery
|
||||||
|
import io
|
||||||
import sys
|
import sys
|
||||||
import time
|
import time
|
||||||
import marshal
|
import marshal
|
||||||
|
@ -588,7 +589,7 @@ def main():
|
||||||
else:
|
else:
|
||||||
progname = args[0]
|
progname = args[0]
|
||||||
sys.path.insert(0, os.path.dirname(progname))
|
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')
|
code = compile(fp.read(), progname, 'exec')
|
||||||
spec = importlib.machinery.ModuleSpec(name='__main__', loader=None,
|
spec = importlib.machinery.ModuleSpec(name='__main__', loader=None,
|
||||||
origin=progname)
|
origin=progname)
|
||||||
|
|
|
@ -49,6 +49,7 @@
|
||||||
"""
|
"""
|
||||||
__all__ = ['Trace', 'CoverageResults']
|
__all__ = ['Trace', 'CoverageResults']
|
||||||
|
|
||||||
|
import io
|
||||||
import linecache
|
import linecache
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
@ -716,7 +717,7 @@ def parse_ignore_dir(s):
|
||||||
sys.argv = [opts.progname, *opts.arguments]
|
sys.argv = [opts.progname, *opts.arguments]
|
||||||
sys.path[0] = os.path.dirname(opts.progname)
|
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')
|
code = compile(fp.read(), opts.progname, 'exec')
|
||||||
# try to emulate __main__ namespace as much as possible
|
# try to emulate __main__ namespace as much as possible
|
||||||
globs = {
|
globs = {
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
Use :func:`io.open_code` for files to be executed instead of raw :func:`open`
|
Loading…
Reference in New Issue