New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
uu-codec trailing garbage workaround is Python 2 code #66596
Comments
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 |
Do you want to provide a patch Martin? |
Here are two patches: a test and a fix. I’m not sure if it is okay to add a test for the “codecs” module with the tests for the “uu” module; it was easier that way because I am basically running the same test over the two different APIs. |
New changeset ad89a652b4ed by Serhiy Storchaka in branch '3.4': New changeset b18ef4a3e7c1 by Serhiy Storchaka in branch 'default': New changeset 7b82b58b8329 by Serhiy Storchaka in branch '2.7': |
I think it is safer now just fix existing code than replace it with totally different code with the risk of incompatibility. In any case uu_codec needs rewriting because currently it doesn't support incremental encoding and decoding. Thank you for your contribution Martin. And if you are going to do further contribution, please submit a contributor form (https://www.python.org/psf/contrib/). Few notes. It is more handy to provide all changes as one patch. And your patches contain trailing spaces in blank lines. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: