Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 827fdaa

Browse files
committed
Issue #10552: Partially fixed a sort error in Tools/unicode/gencodec.py
1 parent f498b75 commit 827fdaa

1 file changed

Lines changed: 10 additions & 7 deletions

File tree

Tools/unicode/gencodec.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@
3434
# Standard undefined Unicode code point
3535
UNI_UNDEFINED = chr(0xFFFE)
3636

37+
# Placeholder for a missing codepoint
38+
MISSING_CODE = -1
39+
3740
mapRE = re.compile('((?:0x[0-9a-fA-F]+\+?)+)'
3841
'\s+'
3942
'((?:(?:0x[0-9a-fA-Z]+|<[A-Za-z]+>)\+?)*)'
@@ -52,16 +55,16 @@ def parsecodes(codes, len=len, range=range):
5255
5356
"""
5457
if not codes:
55-
return None
58+
return MISSING_CODE
5659
l = codes.split('+')
5760
if len(l) == 1:
5861
return int(l[0],16)
5962
for i in range(len(l)):
6063
try:
6164
l[i] = int(l[i],16)
6265
except ValueError:
63-
l[i] = None
64-
l = [x for x in l if x is not None]
66+
l[i] = MISSING_CODE
67+
l = [x for x in l if x != MISSING_CODE]
6568
if len(l) == 1:
6669
return l[0]
6770
else:
@@ -113,7 +116,7 @@ def readmap(filename):
113116
# mappings to None for the rest
114117
if len(identity) >= len(unmapped):
115118
for enc in unmapped:
116-
enc2uni[enc] = (None, "")
119+
enc2uni[enc] = (MISSING_CODE, "")
117120
enc2uni['IDENTITY'] = 256
118121

119122
return enc2uni
@@ -211,7 +214,7 @@ def python_tabledef_code(varname, map, comments=1, key_precision=2):
211214
(mapkey, mapcomment) = mapkey
212215
if isinstance(mapvalue, tuple):
213216
(mapvalue, mapcomment) = mapvalue
214-
if mapkey is None:
217+
if mapkey == MISSING_CODE:
215218
continue
216219
table[mapkey] = (mapvalue, mapcomment)
217220
if mapkey > maxkey:
@@ -223,11 +226,11 @@ def python_tabledef_code(varname, map, comments=1, key_precision=2):
223226
# Create table code
224227
for key in range(maxkey + 1):
225228
if key not in table:
226-
mapvalue = None
229+
mapvalue = MISSING_CODE
227230
mapcomment = 'UNDEFINED'
228231
else:
229232
mapvalue, mapcomment = table[key]
230-
if mapvalue is None:
233+
if mapvalue == MISSING_CODE:
231234
mapchar = UNI_UNDEFINED
232235
else:
233236
if isinstance(mapvalue, tuple):

0 commit comments

Comments
 (0)