[New-bugs-announce] [issue4387] binascii b2a functions accept strings (unicode) as data
Terry J. Reedy
report at bugs.python.org
Sat Nov 22 01:41:19 CET 2008
New submission from Terry J. Reedy <tjreedy at udel.edu>:
Binascii b2a_xxx functions accept 'binary data' and return ascii-encoded
bytes. The corresponding a2b_xxx functions turn the ascii-encoded bytes
back to 'binary data' (bytes). If the binary data is bytes, these
should be inverses of each other.
Somewhat surprisingly to me (because the corresponding base64 module
functions raise "TypeError: expected bytes, not str") 3.0 strings
(unicode) are accepted as 'binary data', though they will not 'round-trip'.
Ascii chars almost do
>>> a='aaaa'
>>> c=b.b2a_base64(a)
>>> c
b'YWFhYQ==\n'
>>> d=b.a2b_base64(c)
>>> d
b'aaaa'
But general unicode chars generate nonsense.
>>> a='\u1000'
>>> c=b.b2a_base64(a)
>>> c
b'4YCA\n'
>>> d=b.a2b_base64(c)
>>> d
b'\xe1\x80\x80'
I also tried b2a_uu.
Is this a bug?
----------
components: Extension Modules
messages: 76226
nosy: tjreedy
severity: normal
status: open
title: binascii b2a functions accept strings (unicode) as data
versions: Python 3.0
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue4387>
_______________________________________
More information about the New-bugs-announce
mailing list