Add _codecs.charmap_build, fix other _codecs issues

This commit is contained in:
Noah committed 2020-04-14 14:59:54 -05:00
1 parent 942a7d612c
commit a540f042e8
2 files changed
+6 -5

No files matched your search

+6 -3
View File
@@ -239,6 +239,9 @@ def charmap_encode(obj, errors='strict', mapping='latin-1'):
res = bytes(res)
return res, len(res)
def charmap_build(s):
return {ord(c): i for i, c in enumerate(s)}
if sys.maxunicode == 65535:
unicode_bytes = 2
else:
@@ -1525,11 +1528,11 @@ def charmapencode_output(c, mapping):
rep = mapping[c]
if isinstance(rep, int) or isinstance(rep, int):
if rep < 256:
return chr(rep)
return rep
else:
raise TypeError("character mapping must be in range(256)")
elif isinstance(rep, str):
return rep
return ord(rep)
elif rep == None:
raise KeyError("character maps to <undefined>")
else:
@@ -1579,7 +1582,7 @@ def PyUnicode_DecodeCharmap(s, size, mapping, errors):
#/* Get mapping (char ordinal -> integer, Unicode char or None) */
ch = s[inpos]
try:
x = mapping[ord(ch)]
x = mapping[ch]
if isinstance(x, int):
if x < 65536:
p += chr(x)
-2
View File
@@ -2219,8 +2219,6 @@ class UnicodeTest(string_tests.CommonTest,
for encoding in ('utf-8',):
self.assertEqual(str(u.encode(encoding),encoding), u)
# TODO: RUSTPYTHON
@unittest.expectedFailure
def test_codecs_charmap(self):
# 0-127
s = bytes(range(128))