homepage

This issue tracker has been migrated to GitHub , and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

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 <1366810993.66.0.854145251684.issue7475@psf.upfronthosting.co.za>
In-reply-to
Content
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 codecs.py source code:
 http://hg.python.org/cpython-fullhistory/rev/8ea2cb1ec598
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")
b'ZXhhbXBsZQ==\n'
>>> decode(b"ZXhhbXBsZQ==\n", "base64_codec")
b'example'
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/base64_codec.py", line 20, in base64_decode
 return (base64.decodebytes(input), len(input))
 File "/usr/lib64/python3.2/base64.py", 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.
History
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: <1366810993.66.0.854145251684.issue7475@psf.upfronthosting.co.za>
2013年04月24日 13:43:13ncoghlanlinkissue7475 messages
2013年04月24日 13:43:13ncoghlancreate

AltStyle によって変換されたページ (->オリジナル) /