mirror of
https://github.com/python/cpython.git
synced 2025-12-08 06:10:17 +00:00
[3.9] gh-103935: Use io.open_code() when executing code in trace and profile modules (GH-103947) (#103953)
Co-authored-by: Tian Gao <gaogaotiantian@hotmail.com>
This commit is contained in:
parent
98016f7c92
commit
d1645ce4f1
4 changed files with 7 additions and 3 deletions
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -49,6 +49,7 @@
|
|||
"""
|
||||
__all__ = ['Trace', 'CoverageResults']
|
||||
|
||||
import io
|
||||
import linecache
|
||||
import os
|
||||
import sys
|
||||
|
|
@ -716,7 +717,7 @@ def parse_ignore_dir(s):
|
|||
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 = {
|
||||
|
|
|
|||
|
|
@ -0,0 +1 @@
|
|||
Use :func:`io.open_code` for files to be executed instead of raw :func:`open`
|
||||
Loading…
Add table
Add a link
Reference in a new issue