| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1316,16 +1316,10 @@ encodings. | |||
| 1316 | 1316 | | | | code actually uses UTF-8 | | |
| 1317 | 1317 | | | | by default. | | |
| 1318 | 1318 | +--------------------+---------+---------------------------+ | |
| 1319 | - | unicode_internal | | Return the internal | | ||
| 1320 | - | | | representation of the | | ||
| 1321 | - | | | operand. Stateful codecs | | ||
| 1322 | - | | | are not supported. | | ||
| 1323 | - | | | | | ||
| 1324 | - | | | .. deprecated:: 3.3 | | ||
| 1325 | - | | | This representation is | | ||
| 1326 | - | | | obsoleted by | | ||
| 1327 | - | | | :pep:`393`. | | ||
| 1328 | - +--------------------+---------+---------------------------+ | ||
| 1319 | + | ||
| 1320 | + .. versionchanged:: 3.8 | ||
| 1321 | + "unicode_internal" codec is removed. | ||
| 1322 | + | ||
| 1329 | 1323 | ||
| 1330 | 1324 | .. _binary-transforms: | |
| 1331 | 1325 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -573,6 +573,9 @@ The following features and APIs have been removed from Python 3.8: | |||
| 573 | 573 | * Removed the ``doctype()`` method of :class:`~xml.etree.ElementTree.XMLParser`. | |
| 574 | 574 | (Contributed by Serhiy Storchaka in :issue:`29209`.) | |
| 575 | 575 | ||
| 576 | + * "unicode_internal" codec is removed. | ||
| 577 | + (Contributed by Inada Naoki in :issue:`36297`.) | ||
| 578 | + | ||
| 576 | 579 | ||
| 577 | 580 | Porting to Python 3.8 | |
| 578 | 581 | ===================== | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -896,15 +896,6 @@ PyAPI_FUNC(PyObject*) PyUnicode_EncodeRawUnicodeEscape( | |||
| 896 | 896 | Py_ssize_t length /* Number of Py_UNICODE chars to encode */ | |
| 897 | 897 | ) Py_DEPRECATED(3.3); | |
| 898 | 898 | ||
| 899 | - /* --- Unicode Internal Codec --------------------------------------------- */ | ||
| 900 | - | ||
| 901 | - /* Only for internal use in _codecsmodule.c */ | ||
| 902 | - PyObject *_PyUnicode_DecodeUnicodeInternal( | ||
| 903 | - const char *string, | ||
| 904 | - Py_ssize_t length, | ||
| 905 | - const char *errors | ||
| 906 | - ); | ||
| 907 | - | ||
| 908 | 899 | /* --- Latin-1 Codecs ----------------------------------------------------- */ | |
| 909 | 900 | ||
| 910 | 901 | PyAPI_FUNC(PyObject*) _PyUnicode_AsLatin1String( | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -211,42 +211,6 @@ def test_charmapencode(self): | |||
| 211 | 211 | charmap[ord("?")] = "XYZ" # wrong type in mapping | |
| 212 | 212 | self.assertRaises(TypeError, codecs.charmap_encode, sin, "replace", charmap) | |
| 213 | 213 | ||
| 214 | - def test_decodeunicodeinternal(self): | ||
| 215 | - with test.support.check_warnings(('unicode_internal codec has been ' | ||
| 216 | - 'deprecated', DeprecationWarning)): | ||
| 217 | - self.assertRaises( | ||
| 218 | - UnicodeDecodeError, | ||
| 219 | - b"\x00\x00\x00\x00\x00".decode, | ||
| 220 | - "unicode-internal", | ||
| 221 | - ) | ||
| 222 | - if len('\0'.encode('unicode-internal')) == 4: | ||
| 223 | - def handler_unicodeinternal(exc): | ||
| 224 | - if not isinstance(exc, UnicodeDecodeError): | ||
| 225 | - raise TypeError("don't know how to handle %r" % exc) | ||
| 226 | - return ("\x01", 1) | ||
| 227 | - | ||
| 228 | - self.assertEqual( | ||
| 229 | - b"\x00\x00\x00\x00\x00".decode("unicode-internal", "ignore"), | ||
| 230 | - "\u0000" | ||
| 231 | - ) | ||
| 232 | - | ||
| 233 | - self.assertEqual( | ||
| 234 | - b"\x00\x00\x00\x00\x00".decode("unicode-internal", "replace"), | ||
| 235 | - "\u0000\ufffd" | ||
| 236 | - ) | ||
| 237 | - | ||
| 238 | - self.assertEqual( | ||
| 239 | - b"\x00\x00\x00\x00\x00".decode("unicode-internal", "backslashreplace"), | ||
| 240 | - "\u0000\\x00" | ||
| 241 | - ) | ||
| 242 | - | ||
| 243 | - codecs.register_error("test.hui", handler_unicodeinternal) | ||
| 244 | - | ||
| 245 | - self.assertEqual( | ||
| 246 | - b"\x00\x00\x00\x00\x00".decode("unicode-internal", "test.hui"), | ||
| 247 | - "\u0000\u0001\u0000" | ||
| 248 | - ) | ||
| 249 | - | ||
| 250 | 214 | def test_callbacks(self): | |
| 251 | 215 | def handler1(exc): | |
| 252 | 216 | r = range(exc.start, exc.end) | |
@@ -794,16 +758,13 @@ def test_badhandlerresults(self): | |||
| 794 | 758 | ("ascii", b"\xff"), | |
| 795 | 759 | ("utf-8", b"\xff"), | |
| 796 | 760 | ("utf-7", b"+x-"), | |
| 797 | - ("unicode-internal", b"\x00"), | ||
| 798 | 761 | ): | |
| 799 | - with test.support.check_warnings(): | ||
| 800 | - # unicode-internal has been deprecated | ||
| 801 | - self.assertRaises( | ||
| 802 | - TypeError, | ||
| 803 | - bytes.decode, | ||
| 804 | - enc, | ||
| 805 | - "test.badhandler" | ||
| 806 | - ) | ||
| 762 | + self.assertRaises( | ||
| 763 | + TypeError, | ||
| 764 | + bytes.decode, | ||
| 765 | + enc, | ||
| 766 | + "test.badhandler" | ||
| 767 | + ) | ||
| 807 | 768 | ||
| 808 | 769 | def test_lookup(self): | |
| 809 | 770 | self.assertEqual(codecs.strict_errors, codecs.lookup_error("strict")) | |
@@ -1013,7 +974,6 @@ def test_mutatingdecodehandler(self): | |||
| 1013 | 974 | ("utf-32", b"\xff"), | |
| 1014 | 975 | ("unicode-escape", b"\\u123g"), | |
| 1015 | 976 | ("raw-unicode-escape", b"\\u123g"), | |
| 1016 | - ("unicode-internal", b"\xff"), | ||
| 1017 | 977 | ] | |
| 1018 | 978 | ||
| 1019 | 979 | def replacing(exc): | |
@@ -1024,11 +984,9 @@ def replacing(exc): | |||
| 1024 | 984 | raise TypeError("don't know how to handle %r" % exc) | |
| 1025 | 985 | codecs.register_error("test.replacing", replacing) | |
| 1026 | 986 | ||
| 1027 | - with test.support.check_warnings(): | ||
| 1028 | - # unicode-internal has been deprecated | ||
| 1029 | - for (encoding, data) in baddata: | ||
| 1030 | - with self.assertRaises(TypeError): | ||
| 1031 | - data.decode(encoding, "test.replacing") | ||
| 987 | + for (encoding, data) in baddata: | ||
| 988 | + with self.assertRaises(TypeError): | ||
| 989 | + data.decode(encoding, "test.replacing") | ||
| 1032 | 990 | ||
| 1033 | 991 | def mutating(exc): | |
| 1034 | 992 | if isinstance(exc, UnicodeDecodeError): | |
@@ -1039,10 +997,8 @@ def mutating(exc): | |||
| 1039 | 997 | codecs.register_error("test.mutating", mutating) | |
| 1040 | 998 | # If the decoder doesn't pick up the modified input the following | |
| 1041 | 999 | # will lead to an endless loop | |
| 1042 | - with test.support.check_warnings(): | ||
| 1043 | - # unicode-internal has been deprecated | ||
| 1044 | - for (encoding, data) in baddata: | ||
| 1045 | - self.assertEqual(data.decode(encoding, "test.mutating"), "\u4242") | ||
| 1000 | + for (encoding, data) in baddata: | ||
| 1001 | + self.assertEqual(data.decode(encoding, "test.mutating"), "\u4242") | ||
| 1046 | 1002 | ||
| 1047 | 1003 | # issue32583 | |
| 1048 | 1004 | def test_crashing_decode_handler(self): | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1239,16 +1239,6 @@ def test_errors(self): | |||
| 1239 | 1239 | self.assertEqual(decode(br"[\x0]\x0", "replace"), (b"[?]?", 8)) | |
| 1240 | 1240 | ||
| 1241 | 1241 | ||
| 1242 | - class RecodingTest(unittest.TestCase): | ||
| 1243 | - def test_recoding(self): | ||
| 1244 | - f = io.BytesIO() | ||
| 1245 | - with codecs.EncodedFile(f, "unicode_internal", "utf-8") as f2: | ||
| 1246 | - f2.write("a") | ||
| 1247 | - # Python used to crash on this at exit because of a refcount | ||
| 1248 | - # bug in _codecsmodule.c | ||
| 1249 | - | ||
| 1250 | - self.assertTrue(f.closed) | ||
| 1251 | - | ||
| 1252 | 1242 | # From RFC 3492 | |
| 1253 | 1243 | punycode_testcases = [ | |
| 1254 | 1244 | # A Arabic (Egyptian): | |
@@ -1378,87 +1368,6 @@ def test_decode(self): | |||
| 1378 | 1368 | self.assertEqual(uni, puny.decode("punycode")) | |
| 1379 | 1369 | ||
| 1380 | 1370 | ||
| 1381 | - class UnicodeInternalTest(unittest.TestCase): | ||
| 1382 | - @unittest.skipUnless(SIZEOF_WCHAR_T == 4, 'specific to 32-bit wchar_t') | ||
| 1383 | - def test_bug1251300(self): | ||
| 1384 | - # Decoding with unicode_internal used to not correctly handle "code | ||
| 1385 | - # points" above 0x10ffff on UCS-4 builds. | ||
| 1386 | - ok = [ | ||
| 1387 | - (b"\x00\x10\xff\xff", "\U0010ffff"), | ||
| 1388 | - (b"\x00\x00\x01\x01", "\U00000101"), | ||
| 1389 | - (b"", ""), | ||
| 1390 | - ] | ||
| 1391 | - not_ok = [ | ||
| 1392 | - b"\x7f\xff\xff\xff", | ||
| 1393 | - b"\x80\x00\x00\x00", | ||
| 1394 | - b"\x81\x00\x00\x00", | ||
| 1395 | - b"\x00", | ||
| 1396 | - b"\x00\x00\x00\x00\x00", | ||
| 1397 | - ] | ||
| 1398 | - for internal, uni in ok: | ||
| 1399 | - if sys.byteorder == "little": | ||
| 1400 | - internal = bytes(reversed(internal)) | ||
| 1401 | - with support.check_warnings(): | ||
| 1402 | - self.assertEqual(uni, internal.decode("unicode_internal")) | ||
| 1403 | - for internal in not_ok: | ||
| 1404 | - if sys.byteorder == "little": | ||
| 1405 | - internal = bytes(reversed(internal)) | ||
| 1406 | - with support.check_warnings(('unicode_internal codec has been ' | ||
| 1407 | - 'deprecated', DeprecationWarning)): | ||
| 1408 | - self.assertRaises(UnicodeDecodeError, internal.decode, | ||
| 1409 | - "unicode_internal") | ||
| 1410 | - if sys.byteorder == "little": | ||
| 1411 | - invalid = b"\x00\x00\x11\x00" | ||
| 1412 | - invalid_backslashreplace = r"\x00\x00\x11\x00" | ||
| 1413 | - else: | ||
| 1414 | - invalid = b"\x00\x11\x00\x00" | ||
| 1415 | - invalid_backslashreplace = r"\x00\x11\x00\x00" | ||
| 1416 | - with support.check_warnings(): | ||
| 1417 | - self.assertRaises(UnicodeDecodeError, | ||
| 1418 | - invalid.decode, "unicode_internal") | ||
| 1419 | - with support.check_warnings(): | ||
| 1420 | - self.assertEqual(invalid.decode("unicode_internal", "replace"), | ||
| 1421 | - '\ufffd') | ||
| 1422 | - with support.check_warnings(): | ||
| 1423 | - self.assertEqual(invalid.decode("unicode_internal", "backslashreplace"), | ||
| 1424 | - invalid_backslashreplace) | ||
| 1425 | - | ||
| 1426 | - @unittest.skipUnless(SIZEOF_WCHAR_T == 4, 'specific to 32-bit wchar_t') | ||
| 1427 | - def test_decode_error_attributes(self): | ||
| 1428 | - try: | ||
| 1429 | - with support.check_warnings(('unicode_internal codec has been ' | ||
| 1430 | - 'deprecated', DeprecationWarning)): | ||
| 1431 | - b"\x00\x00\x00\x00\x00\x11\x11\x00".decode("unicode_internal") | ||
| 1432 | - except UnicodeDecodeError as ex: | ||
| 1433 | - self.assertEqual("unicode_internal", ex.encoding) | ||
| 1434 | - self.assertEqual(b"\x00\x00\x00\x00\x00\x11\x11\x00", ex.object) | ||
| 1435 | - self.assertEqual(4, ex.start) | ||
| 1436 | - self.assertEqual(8, ex.end) | ||
| 1437 | - else: | ||
| 1438 | - self.fail() | ||
| 1439 | - | ||
| 1440 | - @unittest.skipUnless(SIZEOF_WCHAR_T == 4, 'specific to 32-bit wchar_t') | ||
| 1441 | - def test_decode_callback(self): | ||
| 1442 | - codecs.register_error("UnicodeInternalTest", codecs.ignore_errors) | ||
| 1443 | - decoder = codecs.getdecoder("unicode_internal") | ||
| 1444 | - with support.check_warnings(('unicode_internal codec has been ' | ||
| 1445 | - 'deprecated', DeprecationWarning)): | ||
| 1446 | - ab = "ab".encode("unicode_internal").decode() | ||
| 1447 | - ignored = decoder(bytes("%s\x22\x22\x22\x22%s" % (ab[:4], ab[4:]), | ||
| 1448 | - "ascii"), | ||
| 1449 | - "UnicodeInternalTest") | ||
| 1450 | - self.assertEqual(("ab", 12), ignored) | ||
| 1451 | - | ||
| 1452 | - def test_encode_length(self): | ||
| 1453 | - with support.check_warnings(('unicode_internal codec has been ' | ||
| 1454 | - 'deprecated', DeprecationWarning)): | ||
| 1455 | - # Issue 3739 | ||
| 1456 | - encoder = codecs.getencoder("unicode_internal") | ||
| 1457 | - self.assertEqual(encoder("a")[1], 1) | ||
| 1458 | - self.assertEqual(encoder("\xe9\u0142")[1], 2) | ||
| 1459 | - | ||
| 1460 | - self.assertEqual(codecs.escape_encode(br'\x00')[1], 4) | ||
| 1461 | - | ||
| 1462 | 1371 | # From http://www.gnu.org/software/libidn/draft-josefsson-idn-test-vectors.html | |
| 1463 | 1372 | nameprep_tests = [ | |
| 1464 | 1373 | # 3.1 Map to nothing. | |
@@ -1949,7 +1858,6 @@ def test_basic(self): | |||
| 1949 | 1858 | "shift_jisx0213", | |
| 1950 | 1859 | "tis_620", | |
| 1951 | 1860 | "unicode_escape", | |
| 1952 | - "unicode_internal", | ||
| 1953 | 1861 | "utf_16", | |
| 1954 | 1862 | "utf_16_be", | |
| 1955 | 1863 | "utf_16_le", | |
@@ -1969,7 +1877,6 @@ def test_basic(self): | |||
| 1969 | 1877 | # The following encodings don't work in stateful mode | |
| 1970 | 1878 | broken_unicode_with_stateful = [ | |
| 1971 | 1879 | "punycode", | |
| 1972 | - "unicode_internal" | ||
| 1973 | 1880 | ] | |
| 1974 | 1881 | ||
| 1975 | 1882 | ||
@@ -1984,12 +1891,10 @@ def test_basics(self): | |||
| 1984 | 1891 | name = "latin_1" | |
| 1985 | 1892 | self.assertEqual(encoding.replace("_", "-"), name.replace("_", "-")) | |
| 1986 | 1893 | ||
| 1987 | - with support.check_warnings(): | ||
| 1988 | - # unicode-internal has been deprecated | ||
| 1989 | - (b, size) = codecs.getencoder(encoding)(s) | ||
| 1990 | - self.assertEqual(size, len(s), "encoding=%r" % encoding) | ||
| 1991 | - (chars, size) = codecs.getdecoder(encoding)(b) | ||
| 1992 | - self.assertEqual(chars, s, "encoding=%r" % encoding) | ||
| 1894 | + (b, size) = codecs.getencoder(encoding)(s) | ||
| 1895 | + self.assertEqual(size, len(s), "encoding=%r" % encoding) | ||
| 1896 | + (chars, size) = codecs.getdecoder(encoding)(b) | ||
| 1897 | + self.assertEqual(chars, s, "encoding=%r" % encoding) | ||
| 1993 | 1898 | ||
| 1994 | 1899 | if encoding not in broken_unicode_with_stateful: | |
| 1995 | 1900 | # check stream reader/writer | |
@@ -2116,9 +2021,7 @@ def test_bad_decode_args(self): | |||
| 2116 | 2021 | def test_bad_encode_args(self): | |
| 2117 | 2022 | for encoding in all_unicode_encodings: | |
| 2118 | 2023 | encoder = codecs.getencoder(encoding) | |
| 2119 | - with support.check_warnings(): | ||
| 2120 | - # unicode-internal has been deprecated | ||
| 2121 | - self.assertRaises(TypeError, encoder) | ||
| 2024 | + self.assertRaises(TypeError, encoder) | ||
| 2122 | 2025 | ||
| 2123 | 2026 | def test_encoding_map_type_initialized(self): | |
| 2124 | 2027 | from encodings import cp1140 | |
| Back | FazBrowse Home | New Git URL |
0 commit comments