[issue4387] binascii b2a functions accept strings (unicode) as data
report at bugs.python.org
Sat Nov 29 23:48:04 CET 2008
Antoine Pitrou <pitrou at free.fr> added the comment:
It's not /exactly/ nonsense, it seems to assume an utf8 encoding pass is
>>> b'\xe1\x80\x80'.decode('utf8') == '\u1000'
IMO, while accepting unicode strings instead of bytes for the a2b_xx
functions is understandable (because in practice only ASCII characters
are allowed), it is not acceptable for b2a_xx functions to accept
unicode strings instead of bytes.
In other words, it might/should be ok for
`binascii.a2b_base64('YWFh\n')` to return the same as
`binascii.a2b_base64('YWFh\n')` (that is, b'aaa'), but
`binascii.b2a_base64('aaa')` should raise a TypeError rather than
applying an utf8 encoding pass before doing the actual b2a encoding.
I think this must be fixed before 3.0 final, and is therefore a release
priority: -> release blocker
Python tracker <report at bugs.python.org>
More information about the Python-bugs-list