Skip to content

Commit 8cf37f2

Browse files
committed
Merge branch 'main' of https://github.com/python/cpython
2 parents 1a2e18b + 5c351fc commit 8cf37f2

File tree

7 files changed

+71
-2
lines changed

7 files changed

+71
-2
lines changed

Doc/whatsnew/3.12.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1374,6 +1374,18 @@ APIs:
13741374
* :meth:`!unittest.TestProgram.usageExit` (:gh:`67048`)
13751375
* :class:`!webbrowser.MacOSX` (:gh:`86421`)
13761376
* :class:`classmethod` descriptor chaining (:gh:`89519`)
1377+
* :mod:`importlib.resources` deprecated methods:
1378+
1379+
* ``contents()``
1380+
* ``is_resource()``
1381+
* ``open_binary()``
1382+
* ``open_text()``
1383+
* ``path()``
1384+
* ``read_binary()``
1385+
* ``read_text()``
1386+
1387+
Use :func:`importlib.resources.files()` instead. Refer to `importlib-resources: Migrating from Legacy
1388+
<https://importlib-resources.readthedocs.io/en/latest/using.html#migrating-from-legacy>`_ (:gh:`106531`)
13771389

13781390
Pending Removal in Python 3.14
13791391
------------------------------

Lib/pdb.py

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@
7676
import dis
7777
import code
7878
import glob
79+
import token
7980
import codeop
8081
import pprint
8182
import signal
@@ -601,6 +602,39 @@ def default(self, line):
601602
except:
602603
self._error_exc()
603604

605+
def _replace_convenience_variables(self, line):
606+
"""Replace the convenience variables in 'line' with their values.
607+
e.g. $foo is replaced by __pdb_convenience_variables["foo"].
608+
Note: such pattern in string literals will be skipped"""
609+
610+
if "$" not in line:
611+
return line
612+
613+
dollar_start = dollar_end = -1
614+
replace_variables = []
615+
try:
616+
for t in tokenize.generate_tokens(io.StringIO(line).readline):
617+
token_type, token_string, start, end, _ = t
618+
if token_type == token.OP and token_string == '$':
619+
dollar_start, dollar_end = start, end
620+
elif start == dollar_end and token_type == token.NAME:
621+
# line is a one-line command so we only care about column
622+
replace_variables.append((dollar_start[1], end[1], token_string))
623+
except tokenize.TokenError:
624+
return line
625+
626+
if not replace_variables:
627+
return line
628+
629+
last_end = 0
630+
line_pieces = []
631+
for start, end, name in replace_variables:
632+
line_pieces.append(line[last_end:start] + f'__pdb_convenience_variables["{name}"]')
633+
last_end = end
634+
line_pieces.append(line[last_end:])
635+
636+
return ''.join(line_pieces)
637+
604638
def precmd(self, line):
605639
"""Handle alias expansion and ';;' separator."""
606640
if not line.strip():
@@ -635,7 +669,7 @@ def precmd(self, line):
635669
line = line[:marker].rstrip()
636670

637671
# Replace all the convenience variables
638-
line = re.sub(r'\$([a-zA-Z_][a-zA-Z0-9_]*)', r'__pdb_convenience_variables["\1"]', line)
672+
line = self._replace_convenience_variables(line)
639673

640674
return line
641675

Lib/test/test_lzma.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1401,6 +1401,14 @@ def test__decode_filter_properties(self):
14011401
self.assertEqual(filterspec["lc"], 3)
14021402
self.assertEqual(filterspec["dict_size"], 8 << 20)
14031403

1404+
# see gh-104282
1405+
filters = [lzma.FILTER_X86, lzma.FILTER_POWERPC,
1406+
lzma.FILTER_IA64, lzma.FILTER_ARM,
1407+
lzma.FILTER_ARMTHUMB, lzma.FILTER_SPARC]
1408+
for f in filters:
1409+
filterspec = lzma._decode_filter_properties(f, b"")
1410+
self.assertEqual(filterspec, {"id": f})
1411+
14041412
def test_filter_properties_roundtrip(self):
14051413
spec1 = lzma._decode_filter_properties(
14061414
lzma.FILTER_LZMA1, b"]\x00\x00\x80\x00")

Lib/test/test_pdb.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -847,9 +847,12 @@ def test_convenience_variables():
847847
848848
>>> with PdbTestInput([ # doctest: +ELLIPSIS, +NORMALIZE_WHITESPACE
849849
... '$_frame.f_lineno', # Check frame convenience variable
850+
... '$ _frame', # This should be a syntax error
850851
... '$a = 10', # Set a convenience variable
851852
... '$a', # Print its value
853+
... 'p "$a"', # Print the string $a
852854
... 'p $a + 2', # Do some calculation
855+
... 'p f"$a = {$a}"', # Make sure $ in string is not converted and f-string works
853856
... 'u', # Switch frame
854857
... '$_frame.f_lineno', # Make sure the frame changed
855858
... '$a', # Make sure the value persists
@@ -869,11 +872,17 @@ def test_convenience_variables():
869872
-> try:
870873
(Pdb) $_frame.f_lineno
871874
3
875+
(Pdb) $ _frame
876+
*** SyntaxError: invalid syntax
872877
(Pdb) $a = 10
873878
(Pdb) $a
874879
10
880+
(Pdb) p "$a"
881+
'$a'
875882
(Pdb) p $a + 2
876883
12
884+
(Pdb) p f"$a = {$a}"
885+
'$a = 10'
877886
(Pdb) u
878887
> <doctest test.test_pdb.test_convenience_variables[1]>(2)test_function()
879888
-> util_function()
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Fix null pointer dereference in :func:`lzma._decode_filter_properties`
2+
due to improper handling of BCJ filters with properties of zero length.
3+
Patch by Radislav Chugunov.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Improve handling of pdb convenience variables to avoid replacing string contents.

Modules/_lzmamodule.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,9 @@ build_filter_spec(const lzma_filter *f)
492492
case LZMA_FILTER_ARMTHUMB:
493493
case LZMA_FILTER_SPARC: {
494494
lzma_options_bcj *options = f->options;
495-
ADD_FIELD(options, start_offset);
495+
if (options) {
496+
ADD_FIELD(options, start_offset);
497+
}
496498
break;
497499
}
498500
default:

0 commit comments

Comments
 (0)