diff --git a/powerline/lib/unicode.py b/powerline/lib/unicode.py index b100b18f..8a720036 100644 --- a/powerline/lib/unicode.py +++ b/powerline/lib/unicode.py @@ -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. ''' diff --git a/tests/test_lib.py b/tests/test_lib.py index 06b28fa7..1766f6a1 100644 --- a/tests/test_lib.py +++ b/tests/test_lib.py @@ -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))