Author ncoghlan
Recipients barry, belopolsky, benjamin.peterson, cben, eric.araujo, ezio.melotti, flox, georg.brandl, gregory.p.smith, gvanrossum, jcea, lemburg, loewis, ncoghlan, pconnell, petri.lehtinen, r.david.murray, ssbarnea, vstinner
Date 2013-04-24.13:43:13
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
It turns out MAL added the convenience API I'm looking for back in 2004, it just didn't get documented, and is hidden behind the "from _codecs import *" call in the source code:

So, all the way from 2.4 to 2.7 you can write:

  from codecs import encode
  result = encode(data, "base64")

It works in 3.x as well, you just need to add the "_codec" to the end to account for the missing aliases:

>>> encode(b"example", "base64_codec")
>>> decode(b"ZXhhbXBsZQ==\n", "base64_codec")

Note that the convenience functions omit the extra checks that are part of the methods (although I admit the specific error here is rather quirky):

>>> b"ZXhhbXBsZQ==\n".decode("base64_codec")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib64/python3.2/encodings/", line 20, in base64_decode
    return (base64.decodebytes(input), len(input))
  File "/usr/lib64/python3.2/", line 359, in decodebytes
    raise TypeError("expected bytes, not %s" % s.__class__.__name__)
TypeError: expected bytes, not memoryview

I'me going to create some additional issues, so this one can return to just being about restoring the missing aliases.
Date User Action Args
2013-04-24 13:43:13ncoghlansetrecipients: + ncoghlan, lemburg, gvanrossum, loewis, barry, georg.brandl, gregory.p.smith, jcea, cben, belopolsky, vstinner, benjamin.peterson, ezio.melotti, eric.araujo, r.david.murray, ssbarnea, flox, petri.lehtinen, pconnell
2013-04-24 13:43:13ncoghlansetmessageid: <>
2013-04-24 13:43:13ncoghlanlinkissue7475 messages
2013-04-24 13:43:13ncoghlancreate