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

Greg Ewing greg.ewing at canterbury.ac.nz
Wed Apr 24 01:19:44 CEST 2013


Stephen J. Turnbull wrote:
> By RFC specification, BASE64 is a
> *textual* representation of arbitrary binary data.  (Cf. URIs.)  The
> natural interpretation of .encode('base64') in that context would be
> as a bytes-to-text encoder.  However, ...  In
> practice, we invariably use an ASCII octet stream to carry BASE64-
> encoded data.

As an aside, if we'd had the flexible string representation sooner,
this needn't have been such a big problem. With it, the base64
encoder could return a unicode string with 8-bit representation,
which could then be turned into an ascii byte string with
negligible overhead.

Web developers might grumble about the need for an extra call,
but they can no longer claim it would kill the performance of
their web server.

-- 
Greg


More information about the Python-Dev mailing list