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

Skip to content

Commit 97225da

Browse files
committed
Sort names independent of the Python version. Fix hex constant warning.
Include all First/Last blocks.
1 parent 5b21df4 commit 97225da

1 file changed

Lines changed: 11 additions & 7 deletions

File tree

Tools/unicode/makeunicodedata.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
# 2002-09-11 wd use string methods
1717
# 2002-10-18 mvl update to Unicode 3.2
1818
# 2002-10-22 mvl generate NFC tables
19+
# 2002-11-24 mvl expand all ranges, sort names version-independently
1920
#
2021
# written by Fredrik Lundh ([email protected])
2122
#
@@ -403,10 +404,13 @@ def makeunicodename(unicode, trace):
403404

404405
wordlist = words.items()
405406

406-
# sort on falling frequency
407-
# XXX: different Python versions produce a different order
408-
# for words with equal frequency
409-
wordlist.sort(lambda a, b: len(b[1])-len(a[1]))
407+
# sort on falling frequency, then by name
408+
def cmpwords((aword, alist),(bword, blist)):
409+
r = -cmp(len(alist),len(blist))
410+
if r:
411+
return r
412+
return cmp(aword, bword)
413+
wordlist.sort(cmpwords)
410414

411415
# figure out how many phrasebook escapes we need
412416
escapes = 0
@@ -541,10 +545,10 @@ def __init__(self, filename, exclusions, expand=1):
541545
char = int(s[0], 16)
542546
table[char] = s
543547

544-
# expand first-last ranges (ignore surrogates and private use)
548+
# expand first-last ranges
545549
if expand:
546550
field = None
547-
for i in range(0, 0xD800):
551+
for i in range(0, 0x110000):
548552
s = table[i]
549553
if s:
550554
if s[1][-6:] == "First>":
@@ -587,7 +591,7 @@ def myhash(s, magic):
587591
h = 0
588592
for c in map(ord, s.upper()):
589593
h = (h * magic) + c
590-
ix = h & 0xff000000
594+
ix = h & 0xff000000L
591595
if ix:
592596
h = (h ^ ((ix>>24) & 0xff)) & 0x00ffffff
593597
return h

0 commit comments

Comments
 (0)