Author: Matti Picus <[email protected]>
Branch: unicode-utf8-py3
Changeset: r95440:cf6ed65cb1da
Date: 2018-12-02 13:03 -0800
http://bitbucket.org/pypy/pypy/changeset/cf6ed65cb1da/
Log: test, fix maketrans
diff --git a/pypy/objspace/std/test/test_unicodeobject.py
b/pypy/objspace/std/test/test_unicodeobject.py
--- a/pypy/objspace/std/test/test_unicodeobject.py
+++ b/pypy/objspace/std/test/test_unicodeobject.py
@@ -636,6 +636,8 @@
assert '<i><i><i>c' == 'abababc'.translate(tbl)
tbl = str.maketrans('abc', 'xyz', 'd')
assert 'xyzzy' == 'abdcdcbdddd'.translate(tbl)
+ tbl = str.maketrans({'\xe9': 'a'})
+ assert "[\xe9]".translate(tbl) == "[a]"
raises(TypeError, str.maketrans)
raises(ValueError, str.maketrans, 'abc', 'defg')
diff --git a/pypy/objspace/std/unicodeobject.py
b/pypy/objspace/std/unicodeobject.py
--- a/pypy/objspace/std/unicodeobject.py
+++ b/pypy/objspace/std/unicodeobject.py
@@ -259,12 +259,12 @@
w_key, w_value = space.unpackiterable(w_item, 2)
if space.isinstance_w(w_key, space.w_unicode):
# convert string keys to integer keys
- key = space.utf8_w(w_key)
- if len(key) != 1:
+ if space.len_w(w_key) != 1:
raise oefmt(space.w_ValueError,
"string keys in translate table must be "
"of length 1")
- w_key = space.newint(ord(key[0]))
+ val = space.utf8_w(w_key)
+ w_key = space.newint(rutf8.codepoint_at_pos(val, 0))
else:
# just keep integer keys
try:
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit