8000 Refactor codecs · RustPython/RustPython@f323d14 · GitHub
[go: up one dir, main page]

Skip to content

Commit f323d14

Browse files
committed
Refactor codecs
1 parent 7ac90f5 commit f323d14

File tree

15 files changed

+1448
-666
lines changed
  • common
  • vm/src
  • 15 files changed

    +1448
    -666
    lines changed

    Cargo.lock

    Lines changed: 1 addition & 0 deletions
    Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

    Lib/_pycodecs.py

    Lines changed: 7 additions & 4 deletions
    Original file line numberDiff line numberDiff line change
    @@ -1086,11 +1086,13 @@ def charmapencode_output(c, mapping):
    10861086
    rep = mapping[c]
    10871087
    if isinstance(rep, int) or isinstance(rep, int):
    10881088
    if rep < 256:
    1089-
    return rep
    1089+
    return [rep]
    10901090
    else:
    10911091
    raise TypeError("character mapping must be in range(256)")
    10921092
    elif isinstance(rep, str):
    1093-
    return ord(rep)
    1093+
    return [ord(rep)]
    1094+
    elif isinstance(rep, bytes):
    1095+
    return rep
    10941096
    elif rep == None:
    10951097
    raise KeyError("character maps to <undefined>")
    10961098
    else:
    @@ -1113,12 +1115,13 @@ def PyUnicode_EncodeCharmap(p, size, mapping='latin-1', errors='strict'):
    11131115
    #/* try to encode it */
    11141116
    try:
    11151117
    x = charmapencode_output(ord(p[inpos]), mapping)
    1116-
    res += [x]
    1118+
    res += x
    11171119
    except KeyError:
    11181120
    x = unicode_call_errorhandler(errors, "charmap",
    11191121
    "character maps to <undefined>", p, inpos, inpos+1, False)
    11201122
    try:
    1121-
    res += [charmapencode_output(ord(y), mapping) for y in x[0]]
    1123+
    for y in x[0]:
    1124+
    res += charmapencode_output(ord(y), mapping)
    11221125
    except KeyError:
    11231126
    raise UnicodeEncodeError("charmap", p, inpos, inpos+1,
    11241127
    "character maps to <undefined>")

    Lib/test/test_charmapcodec.py

    Lines changed: 0 additions & 2 deletions
    Original file line numberDiff line numberDiff line change
    @@ -33,8 +33,6 @@ def test_constructorx(self):
    3333
    self.assertEqual(str(b'dxf', codecname), 'dabcf')
    3434
    self.assertEqual(str(b'dxfx', codecname), 'dabcfabc')
    3535

    36-
    # TODO: RUSTPYTHON
    37-
    @unittest.expectedFailure
    3836
    def test_encodex(self):
    3937
    self.assertEqual('abc'.encode(codecname), b'abc')
    4038
    self.assertEqual('xdef'.encode(codecname), b'abcdef')

    Lib/test/test_codeccallbacks.py

    Lines changed: 0 additions & 14 deletions
    < 8000 /div>
    Original file line numberDiff line numberDiff line change
    @@ -203,8 +203,6 @@ def relaxedutf8(exc):
    203203
    self.assertRaises(UnicodeDecodeError, sin.decode,
    204204
    "utf-8", "test.relaxedutf8")
    205205

    206-
    # TODO: RUSTPYTHON
    207-
    @unittest.expectedFailure
    208206
    def test_charmapencode(self):
    209207
    # For charmap encodings the replacement string will be
    210208
    # mapped through the encoding again. This means, that
    @@ -329,8 +327,6 @@ def check_exceptionobjectargs(self, exctype, args, msg):
    329327
    exc = exctype(*args)
    330328
    self.assertEqual(str(exc), msg)
    331329

    332-
    # TODO: RUSTPYTHON
    333-
    @unittest.expectedFailure
    334330
    def test_unicodeencodeerror(self):
    335331
    self.check_exceptionobjectargs(
    336332
    UnicodeEncodeError,
    @@ -363,8 +359,6 @@ def test_unicodeencodeerror(self):
    363359
    "'ascii' codec can't encode character '\\U00010000' in position 0: ouch"
    364360
    )
    365361

    366-
    # TODO: RUSTPYTHON
    367-
    @unittest.expectedFailure
    368362
    def test_unicodedecodeerror(self):
    369363
    self.check_exceptionobjectargs(
    370364
    UnicodeDecodeError,
    @@ -377,8 +371,6 @@ def test_unicodedecodeerror(self):
    377371
    "'ascii' codec can't decode bytes in position 1-2: ouch"
    378372
    )
    379373

    380-
    # TODO: RUSTPYTHON
    381-
    @unittest.expectedFailure
    382374
    def test_unicodetranslateerror(self):
    383375
    self.check_exceptionobjectargs(
    384376
    UnicodeTranslateError,
    @@ -467,8 +459,6 @@ def test_badandgoodignoreexceptions(self):
    467459
    ("", 2)
    468460
    )
    469461

    470-
    # TODO: RUSTPYTHON
    471-
    @unittest.expectedFailure
    472462
    def test_badandgoodreplaceexceptions(self):
    473463
    # "replace" complains about a non-exception passed in
    474464
    self.assertRaises(
    @@ -509,8 +499,6 @@ def test_badandgoodreplaceexceptions(self):
    509499
    ("\ufffd", 2)
    510500
    )
    511501

    512-
    # TODO: RUSTPYTHON
    513-
    @unittest.expectedFailure
    514502
    def test_badandgoodxmlcharrefreplaceexceptions(self):
    515503
    # "xmlcharrefreplace" complains about a non-exception passed in
    516504
    self.assertRaises(
    @@ -1017,8 +1005,6 @@ def __getitem__(self, key):
    10171005
    self.assertRaises(ValueError, codecs.charmap_decode, b"\xff", "strict", D())
    10181006
    self.assertRaises(TypeError, codecs.charmap_decode, b"\xff", "strict", {0xff: sys.maxunicode+1})
    10191007

    1020-
    # TODO: RUSTPYTHON
    1021-
    @unittest.expectedFailure
    10221008
    def test_encodehelper(self):
    10231009
    # enhance coverage of:
    10241010
    # Objects/unicodeobject.c::unicode_encode_call_errorhandler()

    Lib/test/test_logging.py

    Lines changed: 0 additions & 2 deletions
    Original file line numberDiff line numberDiff line change
    @@ -5525,8 +5525,6 @@ def test_encoding_errors_default(self):
    55255525
    self.assertEqual(data, r'\U0001f602: \u2603\ufe0f: The \xd8resund '
    55265526
    r'Bridge joins Copenhagen to Malm\xf6')
    55275527

    5528-
    # TODO: RustPython
    5529-
    @unittest.expectedFailure
    55305528
    def test_encoding_errors_none(self):
    55315529
    # Specifying None should behave as 'strict'
    55325530
    try:

    common/Cargo.toml

    Lines changed: 1 addition & 0 deletions
    Original file line numberDiff line numberDiff line change
    @@ -29,6 +29,7 @@ num-traits = { workspace = true }
    2929
    once_cell = { workspace = true }
    3030
    parking_lot = { workspace = true, optional = true }
    3131
    rand = { workspace = true }
    32+
    unicode_names2 = { workspace = true }
    3233

    3334
    lock_api = "0.4"
    3435
    radium = "0.7"

    0 commit comments

    Comments
     (0)
    0