[New-bugs-announce] [issue22406] uu-codec trailing garbage workaround is Python 2 code

Martin Panter report at bugs.python.org
Sun Sep 14 15:46:54 CEST 2014


New submission from Martin Panter:

The handler for the “Trailing garbage” error for “uu-codec” uses Python 2 code, while the copy in the "uu” module has the correct Python 3 code.

Please change the line at

https://hg.python.org/cpython/file/775453a7b85d/Lib/encodings/uu_codec.py#l57

to look like

https://hg.python.org/cpython/file/775453a7b85d/Lib/uu.py#l148

In particular, drop ord() and use floor division. Better yet, maybe the code could be reused so that there is less duplication!

Demonstration:

>>> codecs.decode(b"begin 666 <data>\n!,___\n \nend\n", "uu-codec")
Traceback (most recent call last):
  File "/usr/lib/python3.4/encodings/uu_codec.py", line 54, in uu_decode
    data = binascii.a2b_uu(s)
binascii.Error: Trailing garbage

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3.4/encodings/uu_codec.py", line 57, in uu_decode
    nbytes = (((ord(s[0])-32) & 63) * 4 + 5) / 3
TypeError: ord() expected string of length 1, but int found

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: decoding with 'uu-codec' codec failed (TypeError: ord() expected string of length 1, but int found)
>>> codecs.decode(b"begin 666 <data>\n!,P  \n \nend\n", "uu-codec")
b'3'  # Expected output for both cases

----------
components: Library (Lib)
messages: 226870
nosy: vadmium
priority: normal
severity: normal
status: open
title: uu-codec trailing garbage workaround is Python 2 code
type: behavior
versions: Python 3.4

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue22406>
_______________________________________


More information about the New-bugs-announce mailing list