Skip to content

Commit a070887

Browse files
Merge branch 'main' into gh-101178-rework-base85
2 parents 60fbd7c + 8d46f96 commit a070887

25 files changed

+216
-210
lines changed

Doc/library/base64.rst

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,14 +267,20 @@ Refer to the documentation of the individual functions for more information.
267267
.. versionadded:: 3.4
268268

269269

270-
.. function:: z85encode(s)
270+
.. function:: z85encode(s, pad=False)
271271

272272
Encode the :term:`bytes-like object` *s* using Z85 (as used in ZeroMQ)
273273
and return the encoded :class:`bytes`. See `Z85 specification
274274
<https://rfc.zeromq.org/spec/32/>`_ for more information.
275275

276+
If *pad* is true, the input is padded with ``b'\0'`` so its length is a
277+
multiple of 4 bytes before encoding.
278+
276279
.. versionadded:: 3.13
277280

281+
.. versionchanged:: next
282+
The *pad* parameter was added.
283+
278284

279285
.. function:: z85decode(s)
280286

Include/internal/pycore_opcode_metadata.h

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Include/internal/pycore_tstate.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ typedef struct _PyJitTracerInitialState {
3737

3838
typedef struct _PyJitTracerPreviousState {
3939
bool dependencies_still_valid;
40-
bool instr_is_super;
4140
int code_max_size;
4241
int code_curr_size;
4342
int instr_oparg;

Include/internal/pycore_uop_ids.h

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Include/internal/pycore_uop_metadata.h

Lines changed: 15 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Lib/_opcode_metadata.py

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Lib/base64.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -508,9 +508,9 @@ def b85decode(b):
508508
)
509509
_z85_encode_translation = bytes.maketrans(_b85alphabet, _z85alphabet)
510510

511-
def z85encode(s):
511+
def z85encode(s, pad=False):
512512
"""Encode bytes-like object b in z85 format and return a bytes object."""
513-
return b85encode(s).translate(_z85_encode_translation)
513+
return b85encode(s, pad).translate(_z85_encode_translation)
514514

515515
def z85decode(s):
516516
"""Decode the z85-encoded bytes-like object or ASCII string b

Lib/test/test_base64.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -709,6 +709,7 @@ def test_z85encode(self):
709709

710710
tests = {
711711
b'': b'',
712+
b'\x86\x4F\xD2\x6F\xB5\x59\xF7\x5B': b'HelloWorld',
712713
b'www.python.org': b'CxXl-AcVLsz/dgCA+t',
713714
bytes(range(255)): b"""009c61o!#m2NH?C3>iWS5d]J*6CRx17-skh9337x"""
714715
b"""ar.{NbQB=+c[cR@eg&FcfFLssg=mfIi5%2YjuU>)kTv.7l}6Nnnj=AD"""
@@ -889,6 +890,21 @@ def test_b85_padding(self):
889890
eq(base64.b85decode(b'czAet'), b"xxxx")
890891
eq(base64.b85decode(b'czAetcmMzZ'), b"xxxxx\x00\x00\x00")
891892

893+
def test_z85_padding(self):
894+
eq = self.assertEqual
895+
896+
eq(base64.z85encode(b"x", pad=True), b'CMmZz')
897+
eq(base64.z85encode(b"xx", pad=True), b'CZ6h*')
898+
eq(base64.z85encode(b"xxx", pad=True), b'CZaDk')
899+
eq(base64.z85encode(b"xxxx", pad=True), b'CZaET')
900+
eq(base64.z85encode(b"xxxxx", pad=True), b'CZaETCMmZz')
901+
902+
eq(base64.z85decode(b'CMmZz'), b"x\x00\x00\x00")
903+
eq(base64.z85decode(b'CZ6h*'), b"xx\x00\x00")
904+
eq(base64.z85decode(b'CZaDk'), b"xxx\x00")
905+
eq(base64.z85decode(b'CZaET'), b"xxxx")
906+
eq(base64.z85decode(b'CZaETCMmZz'), b"xxxxx\x00\x00\x00")
907+
892908
def test_a85decode_errors(self):
893909
base64 = self.module
894910
illegal = (set(range(32)) | set(range(118, 256))) - set(b' \t\n\r\v')

Lib/test/test_capi/test_opt.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3152,6 +3152,47 @@ def f1():
31523152
"""), PYTHON_JIT="1")
31533153
self.assertEqual(result[0].rc, 0, result)
31543154

3155+
def test_143092(self):
3156+
def f1():
3157+
a = "a"
3158+
for i in range(50):
3159+
x = a[i % len(a)]
3160+
3161+
s = ""
3162+
for _ in range(10):
3163+
s += ""
3164+
3165+
class A: ...
3166+
class B: ...
3167+
3168+
match s:
3169+
case int(): ...
3170+
case str(): ...
3171+
case dict(): ...
3172+
3173+
(
3174+
u0,
3175+
*u1,
3176+
u2,
3177+
u4,
3178+
u5,
3179+
u6,
3180+
u7,
3181+
u8,
3182+
u9, u10, u11,
3183+
u12, u13, u14, u15, u16, u17, u18, u19, u20, u21, u22, u23, u24, u25, u26, u27, u28, u29,
3184+
) = [None, None, None, None, None, None, None, None, None, None, None, None, None, None, None,
3185+
None, None, None, None, None, None, None, None, None, None, None, None, None, None, None,
3186+
None, None, None, None, None, None, None, None, None, None, None, None, None, None, None,
3187+
None, None, None, None, None, None, None, None,]
3188+
3189+
s = ""
3190+
for _ in range(10):
3191+
s += ""
3192+
s += ""
3193+
3194+
for i in range(TIER2_THRESHOLD * 10):
3195+
f1()
31553196

31563197
def global_identity(x):
31573198
return x

Lib/test/test_collections.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2135,6 +2135,19 @@ def test_basics(self):
21352135
self.assertEqual(c.setdefault('e', 5), 5)
21362136
self.assertEqual(c['e'], 5)
21372137

2138+
def test_update_reentrant_add_clears_counter(self):
2139+
c = Counter()
2140+
key = object()
2141+
2142+
class Evil(int):
2143+
def __add__(self, other):
2144+
c.clear()
2145+
return NotImplemented
2146+
2147+
c[key] = Evil()
2148+
c.update([key])
2149+
self.assertEqual(c[key], 1)
2150+
21382151
def test_init(self):
21392152
self.assertEqual(list(Counter(self=42).items()), [('self', 42)])
21402153
self.assertEqual(list(Counter(iterable=42).items()), [('iterable', 42)])

0 commit comments

Comments
 (0)