summaryrefslogtreecommitdiff
path: root/Lib/base64.py
diff options
context:
space:
mode:
authorNick Coghlan <ncoghlan@gmail.com>2017-02-09 16:08:17 +0100
committerNick Coghlan <ncoghlan@gmail.com>2017-02-09 16:08:17 +0100
commitc6180bb73c8c7c7f9d8ea9816487b710597b6fc1 (patch)
treefb4a5c18886537b4b7df46ed3b2aa579747ff507 /Lib/base64.py
parent5e0114a832a903518c4af6983161c0c2a8942a24 (diff)
parent819a21a3a4aac38f32e1ba4f68bcef45591fa3f0 (diff)
downloadcpython-c6180bb73c8c7c7f9d8ea9816487b710597b6fc1.tar.gz
Merge issue #26355 fix from Python 3.5
Diffstat (limited to 'Lib/base64.py')
-rwxr-xr-xLib/base64.py5
1 files changed, 2 insertions, 3 deletions
diff --git a/Lib/base64.py b/Lib/base64.py
index adaec1de61..58f6ad6816 100755
--- a/Lib/base64.py
+++ b/Lib/base64.py
@@ -55,8 +55,7 @@ def b64encode(s, altchars=None):
alternative alphabet for the '+' and '/' characters. This allows an
application to e.g. generate url or filesystem safe Base64 strings.
"""
- # 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))
@@ -156,7 +155,7 @@ def b32encode(s):
leftover = len(s) % 5
# Pad the last quantum with zero bits if necessary
if leftover:
- s = s + bytes(5 - leftover) # Don't use += !
+ s = s + b'\0' * (5 - leftover) # Don't use += !
encoded = bytearray()
from_bytes = int.from_bytes
b32tab2 = _b32tab2