Skip to content
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

Closed
vadmium opened this issue Sep 14, 2014 · 5 comments
Closed

uu-codec trailing garbage workaround is Python 2 code #66596

vadmium opened this issue Sep 14, 2014 · 5 comments
Assignees
Labels
easy stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@vadmium
Copy link
Member

vadmium commented Sep 14, 2014

BPO 22406
Nosy @malemburg, @doerwalter, @vadmium, @serhiy-storchaka
Files
  • test.patch: Test
  • uu_codec.patch: Fix
  • 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:

    assignee = 'https://github.com/serhiy-storchaka'
    closed_at = <Date 2014-11-07.12:56:21.744>
    created_at = <Date 2014-09-14.13:46:54.340>
    labels = ['easy', 'type-bug', 'library']
    title = 'uu-codec trailing garbage workaround is Python 2 code'
    updated_at = <Date 2014-11-07.12:56:21.743>
    user = 'https://github.com/vadmium'

    bugs.python.org fields:

    activity = <Date 2014-11-07.12:56:21.743>
    actor = 'serhiy.storchaka'
    assignee = 'serhiy.storchaka'
    closed = True
    closed_date = <Date 2014-11-07.12:56:21.744>
    closer = 'serhiy.storchaka'
    components = ['Library (Lib)']
    creation = <Date 2014-09-14.13:46:54.340>
    creator = 'martin.panter'
    dependencies = []
    files = ['36618', '36619']
    hgrepos = []
    issue_num = 22406
    keywords = ['easy']
    message_count = 5.0
    messages = ['226870', '226877', '226898', '230800', '230803']
    nosy_count = 5.0
    nosy_names = ['lemburg', 'doerwalter', 'python-dev', 'martin.panter', 'serhiy.storchaka']
    pr_nums = []
    priority = 'low'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue22406'
    versions = ['Python 3.4', 'Python 3.5']

    @vadmium
    Copy link
    Member Author

    vadmium commented Sep 14, 2014

    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

    @vadmium vadmium added stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels Sep 14, 2014
    @serhiy-storchaka serhiy-storchaka self-assigned this Sep 14, 2014
    @serhiy-storchaka
    Copy link
    Member

    Do you want to provide a patch Martin?

    @vadmium
    Copy link
    Member Author

    vadmium commented Sep 15, 2014

    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.

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Nov 7, 2014

    New changeset ad89a652b4ed by Serhiy Storchaka in branch '3.4':
    Issue bpo-22406: Fixed the uu_codec codec incorrectly ported to 3.x.
    https://hg.python.org/cpython/rev/ad89a652b4ed

    New changeset b18ef4a3e7c1 by Serhiy Storchaka in branch 'default':
    Issue bpo-22406: Fixed the uu_codec codec incorrectly ported to 3.x.
    https://hg.python.org/cpython/rev/b18ef4a3e7c1

    New changeset 7b82b58b8329 by Serhiy Storchaka in branch '2.7':
    Backported tests for issue bpo-22406.
    https://hg.python.org/cpython/rev/7b82b58b8329

    @serhiy-storchaka
    Copy link
    Member

    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.

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    easy stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants