Issue #25357: Add an optional newline paramer to binascii.b2a_base64().

base64.b64encode() uses it to avoid a memory copy.
This commit is contained in:
Victor Stinner 2015-10-11 11:01:02 +02:00
parent 5df7fddc0c
commit e84c976568
6 changed files with 45 additions and 20 deletions

View file

@ -58,8 +58,7 @@ def b64encode(s, altchars=None):
The encoded byte string is returned.
"""
# Strip off the trailing newline
encoded = binascii.b2a_base64(s)[:-1]
encoded = binascii.b2a_base64(s, newline=False)
if altchars is not None:
assert len(altchars) == 2, repr(altchars)
return encoded.translate(bytes.maketrans(b'+/', altchars))