Skip to content

Commit

Permalink
Remove support for narrow builds (closes #61)
Browse files Browse the repository at this point in the history
The possibility for 'narrow' builds of CPython went away with Python 3.3
  • Loading branch information
SnoopJ committed Sep 21, 2023
1 parent 619dac4 commit 618a15b
Showing 1 changed file with 0 additions and 35 deletions.
35 changes: 0 additions & 35 deletions tests/test_unicodedata2.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,41 +14,6 @@
encoding = 'utf-8'
errors = 'surrogatepass'

MAX_UNICODE_UCS4 = 0x10FFFF

if sys.maxunicode < MAX_UNICODE_UCS4:
# workarounds for Python "narrow" builds with UCS2-only support.

_narrow_unichr = chr

def chr(i):
"""
Return the unicode character whose Unicode code is the integer 'i'.
The valid range is 0 to 0x10FFFF inclusive.
>>> _narrow_unichr(0xFFFF + 1)
Traceback (most recent call last):
File "<stdin>", line 1, in ?
ValueError: unichr() arg not in range(0x10000) (narrow Python build)
>>> chr(0xFFFF + 1) == u'\U00010000'
True
>>> chr(1114111) == u'\U0010FFFF'
True
>>> chr(0x10FFFF + 1)
Traceback (most recent call last):
File "<stdin>", line 1, in ?
ValueError: chr() arg not in range(0x110000)
"""
try:
return _narrow_unichr(i)
except ValueError:
try:
padded_hex_str = hex(i)[2:].zfill(8)
escape_str = "\\U" + padded_hex_str
return escape_str.decode("unicode-escape")
except UnicodeDecodeError:
raise ValueError('chr() arg not in range(0x110000)')


### Run tests

# NOTE: UnicodeMethodsTest upstream tests methods on `str` objects, and
Expand Down

0 comments on commit 618a15b

Please sign in to comment.