R. David Murray <rdmur...@bitdance.com> added the comment:

This reduces to the following:

>>> from binascii import a2b_base64 as f
>>> f(b'MTIzND\nU2Nzg5\n')
b'123456789'
>>> f(b'MTIzND\n')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
binascii.Error: Incorrect padding

That is, decode does its decoding line by line, whereas decodebytes passes the 
entire object to a2b_base64 as a single entity.  Apparently a2b_base64 looks at 
the padding for the entirety of what it is given, which I believe is in 
accordance with the RFC.  This means that decode is fundamentally broken per 
the RFC, and there is no obvious way to fix it without adding an incremental 
decoder to binascii.  And an incremental decoder probably belongs in codecs 
(assuming we ever resolved the transcode interface issue, I can't actually 
remember...).

Note that it will work as long as an "integral" number of base64 encoding units 
are in each line.

----------
nosy: +r.david.murray

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue32491>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to