Issue 34165: uu.decode() raises binascii.Error instead of uu.Error on invalid data
uu.decode() function can leak the internal binascii.Error exception from binascii.a2b_uu() function call instead of the documented uu.Error exception.
Following code demonstrates the issue:
>>> import uu
>>> with open("in.uu", "wb") as fp:
... fp.write(b'begin 0 \n0\xe8')
>>> uu.decode("in.uu", "out.uu")
Traceback (most recent call last):
File "/tmp/python-3.7-bin/lib/python3.7/uu.py", line 148, in decode
data = binascii.a2b_uu(s)
binascii.Error: Illegal char
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/tmp/python-3.7-bin/lib/python3.7/uu.py", line 152, in decode
data = binascii.a2b_uu(s[:nbytes])
binascii.Error: Illegal char
It looks like the the workaround for broken encoders that catches the first binascii.Error exception just lets the second one to propagate if the recovery fails. I would except uu.Error to be raised instead, as that is mentioned in the documentation.