[pypy-commit] pypy default: wrestle more with unicode
bdkearns
noreply at buildbot.pypy.org
Thu Feb 7 08:27:53 CET 2013
Author: Brian Kearns <bdkearns at gmail.com>
Branch:
Changeset: r60923:2c191315b989
Date: 2013-02-06 23:27 -0800
http://bitbucket.org/pypy/pypy/changeset/2c191315b989/
Log: wrestle more with unicode
diff --git a/rpython/rlib/runicode.py b/rpython/rlib/runicode.py
--- a/rpython/rlib/runicode.py
+++ b/rpython/rlib/runicode.py
@@ -31,7 +31,12 @@
ch2 = ord(u[1])
if 0xD800 <= ch1 <= 0xDBFF and 0xDC00 <= ch2 <= 0xDFFF:
return (((ch1 - 0xD800) << 10) | (ch2 - 0xDC00)) + 0x10000
- return ord(u)
+ if not we_are_translated():
+ return ord(u)
+ else:
+ if len(u) == 1:
+ return ord(u[0])
+ raise TypeError
if MAXUNICODE > sys.maxunicode:
# A version of unichr which allows codes outside the BMP
diff --git a/rpython/rlib/test/test_runicode.py b/rpython/rlib/test/test_runicode.py
--- a/rpython/rlib/test/test_runicode.py
+++ b/rpython/rlib/test/test_runicode.py
@@ -16,6 +16,8 @@
py.test.raises(TypeError, runicode.UNICHR, 'abc')
def test_ord():
+ assert runicode.ORD('a') == 97
+ assert runicode.ORD(u'a') == 97
assert runicode.ORD(u'\uffff') == 0xffff
if runicode.MAXUNICODE > 0xffff:
if sys.maxunicode < 0x10000:
More information about the pypy-commit
mailing list