diff --git a/Lib/base64.py b/Lib/base64.py --- a/Lib/base64.py +++ b/Lib/base64.py @@ -28,6 +28,7 @@ bytes_types = (bytes, bytearray) # Types acceptable as binary data +ascii_types = bytes_types + (str,) def _translate(s, altchars): @@ -79,10 +80,10 @@ discarded prior to the padding check. If validate is True, non-base64-alphabet characters in the input result in a binascii.Error. """ - if not isinstance(s, bytes_types): + if not isinstance(s, ascii_types): raise TypeError("expected bytes, not %s" % s.__class__.__name__) if altchars is not None: - if not isinstance(altchars, bytes_types): + if not isinstance(altchars, ascii_types): raise TypeError("expected bytes, not %s" % altchars.__class__.__name__) assert len(altchars) == 2, repr(altchars) @@ -211,7 +212,7 @@ the input is incorrectly padded or if there are non-alphabet characters present in the input. """ - if not isinstance(s, bytes_types): + if not isinstance(s, ascii_types): raise TypeError("expected bytes, not %s" % s.__class__.__name__) quanta, leftover = divmod(len(s), 8) if leftover: @@ -220,7 +221,7 @@ # False, or the character to map the digit 1 (one) to. It should be # either L (el) or I (eye). if map01 is not None: - if not isinstance(map01, bytes_types): + if not isinstance(map01, ascii_types): raise TypeError("expected bytes, not %s" % map01.__class__.__name__) assert len(map01) == 1, repr(map01) s = _translate(s, {b'0': b'O', b'1': map01}) @@ -292,7 +293,7 @@ s were incorrectly padded or if there are non-alphabet characters present in the string. """ - if not isinstance(s, bytes_types): + if not isinstance(s, ascii_types): raise TypeError("expected bytes, not %s" % s.__class__.__name__) if casefold: s = s.upper()