This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Use bytes.fromhex()
Type: enhancement Stage: resolved
Components: Library (Lib) Versions: Python 3.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: python-dev, serhiy.storchaka, vstinner
Priority: normal Keywords: patch

Created on 2016-12-16 20:28 by serhiy.storchaka, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
use_bytes_fromhex.patch serhiy.storchaka, 2016-12-16 20:28 review
Messages (6)
msg283433 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2016-12-16 20:28
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.
msg283740 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2016-12-21 10:59
New changeset 44c62456de75 by Serhiy Storchaka in branch 'default':
Issue #28992: Use bytes.fromhex().
https://hg.python.org/cpython/rev/44c62456de75
msg283747 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2016-12-21 11:52
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
msg283749 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2016-12-21 12:09
New changeset 6ced540a92bc by Serhiy Storchaka in branch 'default':
Fixed a type error introduced in issue #28992.
https://hg.python.org/cpython/rev/6ced540a92bc
msg283750 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2016-12-21 12:09
Oh how could I make such error?! Thanks Victor.
msg283751 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2016-12-21 12:11
Serhiy: "Oh how could I make such error?! Thanks Victor.

It's simple: shit happens :-) Don't worry.
History
Date User Action Args
2022-04-11 14:58:40adminsetgithub: 73178
2016-12-21 19:29:17serhiy.storchakasetstatus: open -> closed
resolution: fixed
2016-12-21 12:11:44vstinnersetmessages: + msg283751
2016-12-21 12:09:56serhiy.storchakasetmessages: + msg283750
2016-12-21 12:09:16python-devsetmessages: + msg283749
2016-12-21 11:52:52vstinnersetstatus: closed -> open

nosy: + vstinner
messages: + msg283747

resolution: fixed -> (no value)
2016-12-21 11:00:02serhiy.storchakasetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2016-12-21 10:59:47python-devsetnosy: + python-dev
messages: + msg283740
2016-12-16 20:28:42serhiy.storchakacreate