diff -r 818f22f9ab02 Lib/email/_encoded_words.py --- a/Lib/email/_encoded_words.py Sat Aug 06 23:29:29 2016 +0300 +++ b/Lib/email/_encoded_words.py Sun Aug 07 12:56:04 2016 +0300 @@ -62,7 +62,7 @@ from email import errors # regex based decoder. _q_byte_subber = functools.partial(re.compile(br'=([a-fA-F0-9]{2})').sub, - lambda m: bytes([int(m.group(1), 16)])) + lambda m: bytes.fromhex(m.group(1))) def decode_q(encoded): encoded = encoded.replace(b'_', b' ') diff -r 818f22f9ab02 Lib/test/multibytecodec_support.py --- a/Lib/test/multibytecodec_support.py Sat Aug 06 23:29:29 2016 +0300 +++ b/Lib/test/multibytecodec_support.py Sun Aug 07 12:56:04 2016 +0300 @@ -338,7 +338,7 @@ class TestBase_Mapping(unittest.TestCase uc = re.findall('', ucmdata) for uni, coded in uc: unich = chr(int(uni, 16)) - codech = bytes(int(c, 16) for c in coded.split()) + codech = bytes.fromhex(coded) self._testpoint(codech, unich) def test_mapping_supplemental(self): diff -r 818f22f9ab02 Lib/test/test_unicode.py --- a/Lib/test/test_unicode.py Sat Aug 06 23:29:29 2016 +0300 +++ b/Lib/test/test_unicode.py Sun Aug 07 12:56:04 2016 +0300 @@ -1769,9 +1769,6 @@ class UnicodeTest(string_tests.CommonTes self.assertEqual(seq.decode('utf-8', 'ignore'), res.replace('\uFFFD', '')) - def to_bytestring(self, seq): - return bytes(int(c, 16) for c in seq.split()) - def assertCorrectUTF8Decoding(self, seq, res, err): """ Check that an invalid UTF-8 sequence raises a UnicodeDecodeError when @@ -1827,7 +1824,7 @@ class UnicodeTest(string_tests.CommonTes ] FFFD = '\ufffd' for seq in sequences: - self.assertCorrectUTF8Decoding(self.to_bytestring(seq), '\ufffd', + self.assertCorrectUTF8Decoding(bytes.fromhex(seq), '\ufffd', 'unexpected end of data') def test_invalid_cb_for_2bytes_seq(self): @@ -1849,7 +1846,7 @@ class UnicodeTest(string_tests.CommonTes ('DF C0', FFFDx2), ('DF FF', FFFDx2), ] for seq, res in sequences: - self.assertCorrectUTF8Decoding(self.to_bytestring(seq), res, + self.assertCorrectUTF8Decoding(bytes.fromhex(seq), res, 'invalid continuation byte') def test_invalid_cb_for_3bytes_seq(self): @@ -1907,7 +1904,7 @@ class UnicodeTest(string_tests.CommonTes ('EF BF C0', FFFDx2), ('EF BF FF', FFFDx2), ] for seq, res in sequences: - self.assertCorrectUTF8Decoding(self.to_bytestring(seq), res, + self.assertCorrectUTF8Decoding(bytes.fromhex(seq), res, 'invalid continuation byte') def test_invalid_cb_for_4bytes_seq(self): @@ -1986,7 +1983,7 @@ class UnicodeTest(string_tests.CommonTes ('F4 8F BF C0', FFFDx2), ('F4 8F BF FF', FFFDx2) ] for seq, res in sequences: - self.assertCorrectUTF8Decoding(self.to_bytestring(seq), res, + self.assertCorrectUTF8Decoding(bytes.fromhex(seq), res, 'invalid continuation byte') def test_codecs_idna(self): diff -r 818f22f9ab02 Lib/urllib/parse.py --- a/Lib/urllib/parse.py Sat Aug 06 23:29:29 2016 +0300 +++ b/Lib/urllib/parse.py Sun Aug 07 12:56:04 2016 +0300 @@ -573,7 +573,7 @@ def unquote_to_bytes(string): # if the function is never called global _hextobyte if _hextobyte is None: - _hextobyte = {(a + b).encode(): bytes([int(a + b, 16)]) + _hextobyte = {(a + b).encode(): bytes.fromhex(a + b) for a in _hexdig for b in _hexdig} for item in bits[1:]: try: