Make unichr() work with characters above U+10000 in UCS-2 builds
This commit is contained in:
parent
305b65f365
commit
87ca9bca5c
|
@ -21,6 +21,17 @@ except ImportError:
|
|||
unichr = chr
|
||||
|
||||
|
||||
if sys.maxunicode < 0x10FFFF:
|
||||
_unichr = unichr
|
||||
|
||||
def unichr(ch):
|
||||
if ch <= sys.maxunicode:
|
||||
return _unichr(ch)
|
||||
else:
|
||||
ch -= 0x10000
|
||||
return _unichr((ch >> 10) + 0xD800) + _unichr((ch & ((1 << 10) - 1)) + 0xDC00)
|
||||
|
||||
|
||||
def u(s):
|
||||
'''Return unicode instance assuming UTF-8 encoded string.
|
||||
'''
|
||||
|
|
|
@ -419,8 +419,7 @@ class TestUnicode(TestCase):
|
|||
self.assertTrue(type('abc') is plu.unicode)
|
||||
|
||||
def test_unichr(self):
|
||||
if not sys.maxunicode < 0x10FFFF:
|
||||
self.assertStringsIdentical('\U0010FFFF', plu.unichr(0x10FFFF))
|
||||
self.assertStringsIdentical('\U0010FFFF', plu.unichr(0x10FFFF))
|
||||
self.assertStringsIdentical('\uFFFF', plu.unichr(0xFFFF))
|
||||
self.assertStringsIdentical('\x20', plu.unichr(0x20))
|
||||
|
||||
|
|
Loading…
Reference in New Issue