Skip to content

Commit 3530708

Browse files
Kolpatimfel
authored andcommitted
implemented charmap_build for codecs
1 parent ddf7583 commit 3530708

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/CodecsModuleBuiltins.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -628,4 +628,26 @@ Object lookup(String encoding) {
628628
}
629629
}
630630
}
631+
632+
// _codecs.lookup(name)
633+
@Builtin(name = "charmap_build", minNumOfPositionalArgs = 1)
634+
@GenerateNodeFactory
635+
abstract static class CharmapBuildNode extends PythonBuiltinNode {
636+
// This is replaced in the core _codecs.py with the full functionality
637+
@Specialization
638+
Object lookup(String chars) {
639+
Map<Integer, Integer> charmap = new HashMap<>();
640+
int pos = 0;
641+
int num = 0;
642+
643+
while (pos < chars.length()) {
644+
int charid = Character.codePointAt(chars, pos);
645+
charmap.put(charid, num);
646+
pos += Character.charCount(charid);
647+
num++;
648+
}
649+
650+
return factory().createDict(charmap);
651+
}
652+
}
631653
}

graalpython/lib-graalpython/_codecs.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -281,11 +281,6 @@ def charmap_decode(string, errors=None, mapping=None):
281281
return __truffle_decode(string, "cp437", errors)
282282

283283

284-
@__builtin__
285-
def charmap_build(mapping):
286-
raise NotImplementedError("charmap_build")
287-
288-
289284
@__builtin__
290285
def readbuffer_encode(data, errors=None):
291286
raise NotImplementedError("readbuffer_encode")

0 commit comments

Comments
 (0)