mirror of
https://github.com/python/cpython.git
synced 2025-12-08 06:10:17 +00:00
gh-141968: Use bytearray.take_bytes in base64 _b32encode and _b32decode (#141971)
This commit is contained in:
parent
2ff8608b4d
commit
2c1fdf3592
2 changed files with 4 additions and 2 deletions
|
|
@ -193,7 +193,7 @@ def _b32encode(alphabet, s):
|
|||
encoded[-3:] = b'==='
|
||||
elif leftover == 4:
|
||||
encoded[-1:] = b'='
|
||||
return bytes(encoded)
|
||||
return encoded.take_bytes()
|
||||
|
||||
def _b32decode(alphabet, s, casefold=False, map01=None):
|
||||
# Delay the initialization of the table to not waste memory
|
||||
|
|
@ -238,7 +238,7 @@ def _b32decode(alphabet, s, casefold=False, map01=None):
|
|||
last = acc.to_bytes(5) # big endian
|
||||
leftover = (43 - 5 * padchars) // 8 # 1: 4, 3: 3, 4: 2, 6: 1
|
||||
decoded[-5:] = last[:leftover]
|
||||
return bytes(decoded)
|
||||
return decoded.take_bytes()
|
||||
|
||||
|
||||
def b32encode(s):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue