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

Use bytes.fromhex() #73178

Closed
serhiy-storchaka opened this issue Dec 16, 2016 · 6 comments
Closed

Use bytes.fromhex() #73178

serhiy-storchaka opened this issue Dec 16, 2016 · 6 comments
Labels
3.7 (EOL) end of life stdlib Python modules in the Lib dir type-feature A feature request or enhancement

Comments

@serhiy-storchaka
Copy link
Member

BPO 28992
Nosy @vstinner, @serhiy-storchaka
Files
  • use_bytes_fromhex.patch
  • 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 = None
    closed_at = <Date 2016-12-21.19:29:17.407>
    created_at = <Date 2016-12-16.20:28:42.597>
    labels = ['3.7', 'type-feature', 'library']
    title = 'Use bytes.fromhex()'
    updated_at = <Date 2016-12-21.19:29:17.406>
    user = 'https://github.com/serhiy-storchaka'

    bugs.python.org fields:

    activity = <Date 2016-12-21.19:29:17.406>
    actor = 'serhiy.storchaka'
    assignee = 'none'
    closed = True
    closed_date = <Date 2016-12-21.19:29:17.407>
    closer = 'serhiy.storchaka'
    components = ['Library (Lib)']
    creation = <Date 2016-12-16.20:28:42.597>
    creator = 'serhiy.storchaka'
    dependencies = []
    files = ['45930']
    hgrepos = []
    issue_num = 28992
    keywords = ['patch']
    message_count = 6.0
    messages = ['283433', '283740', '283747', '283749', '283750', '283751']
    nosy_count = 3.0
    nosy_names = ['vstinner', 'python-dev', 'serhiy.storchaka']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue28992'
    versions = ['Python 3.7']

    @serhiy-storchaka
    Copy link
    Member Author

    Proposed patch makes the code and tests using bytes.fromhex(). The benefit of bytes.fromhex() over manual converting hexadecimals to bytes:

    1. This is the one obvious way to do it.

    2. This is the fastest way to do it.

    @serhiy-storchaka serhiy-storchaka added 3.7 (EOL) end of life stdlib Python modules in the Lib dir type-feature A feature request or enhancement labels Dec 16, 2016
    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Dec 21, 2016

    New changeset 44c62456de75 by Serhiy Storchaka in branch 'default':
    Issue bpo-28992: Use bytes.fromhex().
    https://hg.python.org/cpython/rev/44c62456de75

    @vstinner
    Copy link
    Member

    Unhappy buildbot:

    buildbot.python.org/all/builders/AMD64 Debian root 3.x/builds/103/steps/test/logs/stdio

    Example:

    ======================================================================
    ERROR: test_complex_address_list (test.test_email.test_headerregistry.TestAddressHeader)
    ----------------------------------------------------------------------

    Traceback (most recent call last):
      File "/root/buildarea/3.x.angelico-debian-amd64/build/Lib/test/test_email/test_headerregistry.py", line 1243, in test_complex_address_list
        h = self.make_header('to', source)
      File "/root/buildarea/3.x.angelico-debian-amd64/build/Lib/test/test_email/test_headerregistry.py", line 78, in make_header
        return self.factory(name, value)
      File "/root/buildarea/3.x.angelico-debian-amd64/build/Lib/email/headerregistry.py", line 586, in __call__
        return self[name](name, value)
      File "/root/buildarea/3.x.angelico-debian-amd64/build/Lib/email/headerregistry.py", line 197, in __new__
        cls.parse(value, kwds)
      File "/root/buildarea/3.x.angelico-debian-amd64/build/Lib/email/headerregistry.py", line 337, in parse
        kwds['parse_tree'] = address_list = cls.value_parser(value)
      File "/root/buildarea/3.x.angelico-debian-amd64/build/Lib/email/headerregistry.py", line 328, in value_parser
        address_list, value = parser.get_address_list(value)
      File "/root/buildarea/3.x.angelico-debian-amd64/build/Lib/email/_header_value_parser.py", line 2336, in get_address_list
        token, value = get_address(value)
      File "/root/buildarea/3.x.angelico-debian-amd64/build/Lib/email/_header_value_parser.py", line 2313, in get_address
        token, value = get_group(value)
      File "/root/buildarea/3.x.angelico-debian-amd64/build/Lib/email/_header_value_parser.py", line 2269, in get_group
        token, value = get_display_name(value)
      File "/root/buildarea/3.x.angelico-debian-amd64/build/Lib/email/_header_value_parser.py", line 2095, in get_display_name
        token, value = get_phrase(value)
      File "/root/buildarea/3.x.angelico-debian-amd64/build/Lib/email/_header_value_parser.py", line 1770, in get_phrase
        token, value = get_word(value)
      File "/root/buildarea/3.x.angelico-debian-amd64/build/Lib/email/_header_value_parser.py", line 1751, in get_word
        token, value = get_atom(value)
      File "/root/buildarea/3.x.angelico-debian-amd64/build/Lib/email/_header_value_parser.py", line 1668, in get_atom
        token, value = get_encoded_word(value)
      File "/root/buildarea/3.x.angelico-debian-amd64/build/Lib/email/_header_value_parser.py", line 1444, in get_encoded_word
        text, charset, lang, defects = _ew.decode('=?' + tok + '?=')
      File "/root/buildarea/3.x.angelico-debian-amd64/build/Lib/email/_encoded_words.py", line 166, in decode
        bstring, defects = _cte_decoders[cte](bstring)
      File "/root/buildarea/3.x.angelico-debian-amd64/build/Lib/email/_encoded_words.py", line 69, in decode_q
        return _q_byte_subber(encoded), []
      File "/root/buildarea/3.x.angelico-debian-amd64/build/Lib/email/_encoded_words.py", line 65, in <lambda>
        lambda m: bytes.fromhex(m.group(1)))
    TypeError: fromhex() argument must be str, not bytes

    @vstinner vstinner reopened this Dec 21, 2016
    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Dec 21, 2016

    New changeset 6ced540a92bc by Serhiy Storchaka in branch 'default':
    Fixed a type error introduced in issue bpo-28992.
    https://hg.python.org/cpython/rev/6ced540a92bc

    @serhiy-storchaka
    Copy link
    Member Author

    Oh how could I make such error?! Thanks Victor.

    @vstinner
    Copy link
    Member

    Serhiy: "Oh how could I make such error?! Thanks Victor.

    It's simple: shit happens :-) Don't worry.

    @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
    3.7 (EOL) end of life stdlib Python modules in the Lib dir type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants