Author: fijal
Branch: unicode-utf8
Changeset: r93116:0021cc161b99
Date: 2017-11-21 18:25 +0100
http://bitbucket.org/pypy/pypy/changeset/0021cc161b99/
Log: fix checking for unichr range
diff --git a/pypy/module/__builtin__/operation.py
b/pypy/module/__builtin__/operation.py
--- a/pypy/module/__builtin__/operation.py
+++ b/pypy/module/__builtin__/operation.py
@@ -24,16 +24,15 @@
@unwrap_spec(code=int)
def unichr(space, code):
"Return a Unicode string of one character with the given ordinal."
- try:
- s = rutf8.unichr_as_utf8(code, allow_surrogates=True)
- except ValueError:
- raise oefmt(space.w_ValueError, "unichr() arg out of range")
- if code < 0x80:
+ if code < 0 or code > 0x10FFFF:
+ raise oefmt(space.w_ValueError, "unichr() arg out of range")
+ elif code < 0x80:
flag = rutf8.FLAG_ASCII
elif 0xD800 <= code <= 0xDFFF:
flag = rutf8.FLAG_HAS_SURROGATES
else:
flag = rutf8.FLAG_REGULAR
+ s = rutf8.unichr_as_utf8(code, allow_surrogates=True)
return space.newutf8(s, 1, flag)
def len(space, w_obj):
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit