[Python-Dev] Why can't I encode/decode base64 without importing a module?

Tres Seaver tseaver at palladion.com
Thu Apr 25 15:55:26 CEST 2013


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 04/25/2013 01:43 AM, Antoine Pitrou wrote:
> On Thu, 25 Apr 2013 04:19:36 +0200 Lennart Regebro <regebro at gmail.com>
> wrote:
>> On Thu, Apr 25, 2013 at 3:54 AM, Stephen J. Turnbull
>> <stephen at xemacs.org> wrote:
>>> RFC 4648 repeatedly refers to *characters*, without specifying an 
>>> encoding for them.
> [...]
>> 
>> Base64 is an encoding that transforms between 8-bit streams.
> 
> No, it isn't. What Stephen wrote above.

Stephen was incorrect:  the base64 standard is about encoding a binary
stream (8-bit bites) onto another binary stream (6-bit bytes), but one
which can be safely transmitted over a 7-bit-only medium.  Text in Py3ks
sense is irrelevant.

>> Either you get a "LookupError: unknown encoding: base64", which is
>> what you get now, or you get an UnicodeEncodingError if the text is
>> not ASCII. We don't want the latter, because it means that code that
>> looks fine for the developer breaks in real life because the
>> developer was American
> 
> That's bogus. By the same argument, we should suppress any encoding
> which isn't able to represent all possible unicode strings. That's
> almost all encodings provided by Python (including utf-8, if you
> consider lone surrogates).
> 
> I'm sorry for Americans, but they *still* must know about character 
> encodings, and be ready to handle UnicodeErrors, when using Python 3
> for encoding/decoding bytestrings. There's no way around it.

WHat does that snark have to do with this discussion?  base64 has no more
to do with character set encodings than it does the moon.  It would be a
"transform" (bytes -> bytes), not an "encoding".


Tres.
- -- 
===================================================================
Tres Seaver          +1 540-429-0999          tseaver at palladion.com
Palladion Software   "Excellence by Design"    http://palladion.com
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)
Comment: Using GnuPG with undefined - http://www.enigmail.net/

iEYEARECAAYFAlF5Nc4ACgkQ+gerLs4ltQ7f9ACgx19dzyLXCDzkLkWITSU+7WyD
XEMAn38mZgK8F1/FGWJc+ANOJz2tfHI/
=qpSL
-----END PGP SIGNATURE-----



More information about the Python-Dev mailing list