Mercurial > cpython-lru_cache-weakref
diff Lib/base64.py @ 42911:cb28e14ee808
Changes in anticipation of stricter str vs. bytes enforcement.
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Mon, 27 Aug 2007 20:40:10 +0000 |
| parents | eb45f85c4c79 |
| children | 3f0f1c775d9d |
line wrap: on
line diff
--- a/Lib/base64.py Mon Aug 27 19:07:22 2007 +0000 +++ b/Lib/base64.py Mon Aug 27 20:40:10 2007 +0000 @@ -54,7 +54,7 @@ encoded = binascii.b2a_base64(s)[:-1] if altchars is not None: if not isinstance(altchars, bytes): - altchars = bytes(altchars) + altchars = bytes(altchars, "ascii") assert len(altchars) == 2, repr(altchars) return _translate(encoded, {'+': altchars[0:1], '/': altchars[1:2]}) return encoded @@ -75,7 +75,7 @@ s = bytes(s) if altchars is not None: if not isinstance(altchars, bytes): - altchars = bytes(altchars) + altchars = bytes(altchars, "ascii") assert len(altchars) == 2, repr(altchars) s = _translate(s, {chr(altchars[0]): b'+', chr(altchars[1]): b'/'}) return binascii.a2b_base64(s) @@ -239,7 +239,7 @@ acc = 0 shift = 35 # Process the last, partial quanta - last = binascii.unhexlify(bytes('%010x' % acc)) + last = binascii.unhexlify(bytes('%010x' % acc, "ascii")) if padchars == 0: last = b'' # No characters elif padchars == 1: @@ -323,8 +323,7 @@ def encodestring(s): """Encode a string into multiple lines of base-64 data.""" - if not isinstance(s, bytes): - s = bytes(s) + assert isinstance(s, bytes), repr(s) pieces = [] for i in range(0, len(s), MAXBINSIZE): chunk = s[i : i + MAXBINSIZE] @@ -334,8 +333,7 @@ def decodestring(s): """Decode a string.""" - if not isinstance(s, bytes): - s = bytes(s) + assert isinstance(s, bytes), repr(s) return binascii.a2b_base64(s)
