mirror of
https://github.com/python/cpython.git
synced 2025-09-29 11:45:57 +00:00
[3.11] gh-103578: Fix pdb reading code with non-utf8 encoding (GH-103581) (#103867)
`pdb` should use `io.open_code` to open code to avoid encoding issue.
(cherry picked from commit 31acfd78a0
)
Co-authored-by: Tian Gao <gaogaotiantian@hotmail.com>
This commit is contained in:
parent
d9aafe2499
commit
f11ba1c2de
3 changed files with 8 additions and 1 deletions
|
@ -154,7 +154,7 @@ class _ScriptTarget(str):
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def code(self):
|
def code(self):
|
||||||
with io.open(self) as fp:
|
with io.open_code(self) as fp:
|
||||||
return f"exec(compile({fp.read()!r}, {self!r}, 'exec'))"
|
return f"exec(compile({fp.read()!r}, {self!r}, 'exec'))"
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -2348,6 +2348,12 @@ def bœr():
|
||||||
# verify that pdb found the source of the "frozen" function
|
# verify that pdb found the source of the "frozen" function
|
||||||
self.assertIn('x = "Sentinel string for gh-93696"', stdout, "Sentinel statement not found")
|
self.assertIn('x = "Sentinel string for gh-93696"', stdout, "Sentinel statement not found")
|
||||||
|
|
||||||
|
def test_non_utf8_encoding(self):
|
||||||
|
script_dir = os.path.join(os.path.dirname(__file__), 'encoded_modules')
|
||||||
|
for filename in os.listdir(script_dir):
|
||||||
|
if filename.endswith(".py"):
|
||||||
|
self._run_pdb([os.path.join(script_dir, filename)], 'q')
|
||||||
|
|
||||||
class ChecklineTests(unittest.TestCase):
|
class ChecklineTests(unittest.TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
linecache.clearcache() # Pdb.checkline() uses linecache.getline()
|
linecache.clearcache() # Pdb.checkline() uses linecache.getline()
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
Fixed a bug where :mod:`pdb` crashes when reading source file with different encoding by replacing :func:`io.open` with :func:`io.open_code`. The new method would also call into the hook set by :func:`PyFile_SetOpenCodeHook`.
|
Loading…
Add table
Add a link
Reference in a new issue