diff options
Diffstat (limited to 'Tools/unicode/mkstringprep.py')
| -rw-r--r-- | Tools/unicode/mkstringprep.py | 100 |
1 files changed, 50 insertions, 50 deletions
diff --git a/Tools/unicode/mkstringprep.py b/Tools/unicode/mkstringprep.py index 99fcae7..868f5cd 100644 --- a/Tools/unicode/mkstringprep.py +++ b/Tools/unicode/mkstringprep.py @@ -5,12 +5,12 @@ if sys.maxunicode == 65535: def gen_category(cats): for i in range(0, 0x110000): - if unicodedata.category(unichr(i)) in cats: + if unicodedata.category(chr(i)) in cats: yield(i) def gen_bidirectional(cats): for i in range(0, 0x110000): - if unicodedata.bidirectional(unichr(i)) in cats: + if unicodedata.bidirectional(chr(i)) in cats: yield(i) def compact_set(l): @@ -37,7 +37,7 @@ def compact_set(l): tuple.append((prev,prev+span+1)) else: single.append(prev) - tuple = " + ".join(["range(%d,%d)" % t for t in tuple]) + tuple = " + ".join(["list(range(%d,%d))" % t for t in tuple]) if not single: return "set(%s)" % tuple if not tuple: @@ -106,7 +106,7 @@ for l in data: ########### Generate compact Python versions of the tables ############# -print """# This file is generated by mkstringprep.py. DO NOT EDIT. +print("""# This file is generated by mkstringprep.py. DO NOT EDIT. \"\"\"Library that exposes various tables found in the StringPrep RFC 3454. There are two kinds of tables: sets, for which a member test is provided, @@ -114,9 +114,9 @@ and mappings, for which a mapping function is provided. \"\"\" import unicodedata -""" +""") -print "assert unicodedata.unidata_version == %s" % repr(unicodedata.unidata_version) +print("assert unicodedata.unidata_version == %s" % repr(unicodedata.unidata_version)) # A.1 is the table of unassigned characters # XXX Plane 15 PUA is listed as unassigned in Python. @@ -134,24 +134,24 @@ Cn -= set(range(0xFFFF, 0x110000, 0x10000)) # assert table == Cn -print """ +print(""" def in_table_a1(code): if unicodedata.category(code) != 'Cn': return False c = ord(code) if 0xFDD0 <= c < 0xFDF0: return False return (c & 0xFFFF) not in (0xFFFE, 0xFFFF) -""" +""") # B.1 cannot easily be derived name, table = tables[0] del tables[0] assert name == "B.1" table = sorted(table.keys()) -print """ +print(""" b1_set = """ + compact_set(table) + """ def in_table_b1(code): return ord(code) in b1_set -""" +""") # B.2 and B.3 is case folding. # It takes CaseFolding.txt into account, which is @@ -178,20 +178,20 @@ for k,v in table_b2.items(): b3 = sorted(b3_exceptions.items()) -print """ -b3_exceptions = {""" +print(""" +b3_exceptions = {""") for i,(k,v) in enumerate(b3): - print "0x%x:%s," % (k, repr(v)), + print("0x%x:%s," % (k, repr(v)), end=' ') if i % 4 == 3: - print -print "}" + print() +print("}") -print """ +print(""" def map_table_b3(code): r = b3_exceptions.get(ord(code)) if r is not None: return r return code.lower() -""" +""") def map_table_b3(code): r = b3_exceptions.get(ord(code)) @@ -205,7 +205,7 @@ def map_table_b3(code): def map_table_b2(a): al = map_table_b3(a) b = unicodedata.normalize("NFKC", al) - bl = u"".join([map_table_b3(ch) for ch in b]) + bl = "".join([map_table_b3(ch) for ch in b]) c = unicodedata.normalize("NFKC", bl) if b != c: return c @@ -214,13 +214,13 @@ def map_table_b2(a): specials = {} for k,v in table_b2.items(): - if map(ord, map_table_b2(unichr(k))) != v: + if list(map(ord, map_table_b2(chr(k)))) != v: specials[k] = v # B.3 should not add any additional special cases assert specials == {} -print """ +print(""" def map_table_b2(a): al = map_table_b3(a) b = unicodedata.normalize("NFKC", al) @@ -230,7 +230,7 @@ def map_table_b2(a): return c else: return al -""" +""") # C.1.1 is a table with a single character name, table = tables[0] @@ -238,10 +238,10 @@ del tables[0] assert name == "C.1.1" assert table == {0x20:0x20} -print """ +print(""" def in_table_c11(code): return code == u" " -""" +""") # C.1.2 is the rest of all space characters name, table = tables[0] @@ -252,13 +252,13 @@ assert name == "C.1.2" # Zs = set(gen_category(["Zs"])) - set([0x20]) # assert Zs == table -print """ +print(""" def in_table_c12(code): return unicodedata.category(code) == "Zs" and code != u" " def in_table_c11_c12(code): return unicodedata.category(code) == "Zs" -""" +""") # C.2.1 ASCII control characters name, table_c21 = tables[0] @@ -270,10 +270,10 @@ Cc_ascii = Cc & set(range(128)) table_c21 = set(table_c21.keys()) assert Cc_ascii == table_c21 -print """ +print(""" def in_table_c21(code): return ord(code) < 128 and unicodedata.category(code) == "Cc" -""" +""") # C.2.2 Non-ASCII control characters. It also includes # a number of characters in category Cf. @@ -288,7 +288,7 @@ assert len(Cc_nonascii - table_c22) == 0 specials = list(table_c22 - Cc_nonascii) specials.sort() -print """c22_specials = """ + compact_set(specials) + """ +print("""c22_specials = """ + compact_set(specials) + """ def in_table_c22(code): c = ord(code) if c < 128: return False @@ -298,7 +298,7 @@ def in_table_c22(code): def in_table_c21_c22(code): return unicodedata.category(code) == "Cc" or \\ ord(code) in c22_specials -""" +""") # C.3 Private use name, table = tables[0] @@ -308,10 +308,10 @@ assert name == "C.3" Co = set(gen_category(["Co"])) assert set(table.keys()) == Co -print """ +print(""" def in_table_c3(code): return unicodedata.category(code) == "Co" -""" +""") # C.4 Non-character code points, xFFFE, xFFFF # plus process internal codes @@ -319,19 +319,19 @@ name, table = tables[0] del tables[0] assert name == "C.4" -nonchar = set(range(0xFDD0,0xFDF0) + - range(0xFFFE,0x110000,0x10000) + - range(0xFFFF,0x110000,0x10000)) +nonchar = set(range(0xFDD0,0xFDF0)) +nonchar.update(range(0xFFFE,0x110000,0x10000)) +nonchar.update(range(0xFFFF,0x110000,0x10000)) table = set(table.keys()) assert table == nonchar -print """ +print(""" def in_table_c4(code): c = ord(code) if c < 0xFDD0: return False if c < 0xFDF0: return True return (ord(code) & 0xFFFF) in (0xFFFE, 0xFFFF) -""" +""") # C.5 Surrogate codes name, table = tables[0] @@ -341,10 +341,10 @@ assert name == "C.5" Cs = set(gen_category(["Cs"])) assert set(table.keys()) == Cs -print """ +print(""" def in_table_c5(code): return unicodedata.category(code) == "Cs" -""" +""") # C.6 Inappropriate for plain text name, table = tables[0] @@ -353,11 +353,11 @@ assert name == "C.6" table = sorted(table.keys()) -print """ +print(""" c6_set = """ + compact_set(table) + """ def in_table_c6(code): return ord(code) in c6_set -""" +""") # C.7 Inappropriate for canonical representation name, table = tables[0] @@ -366,11 +366,11 @@ assert name == "C.7" table = sorted(table.keys()) -print """ +print(""" c7_set = """ + compact_set(table) + """ def in_table_c7(code): return ord(code) in c7_set -""" +""") # C.8 Change display properties or are deprecated name, table = tables[0] @@ -379,11 +379,11 @@ assert name == "C.8" table = sorted(table.keys()) -print """ +print(""" c8_set = """ + compact_set(table) + """ def in_table_c8(code): return ord(code) in c8_set -""" +""") # C.9 Tagging characters name, table = tables[0] @@ -392,11 +392,11 @@ assert name == "C.9" table = sorted(table.keys()) -print """ +print(""" c9_set = """ + compact_set(table) + """ def in_table_c9(code): return ord(code) in c9_set -""" +""") # D.1 Characters with bidirectional property "R" or "AL" name, table = tables[0] @@ -406,10 +406,10 @@ assert name == "D.1" RandAL = set(gen_bidirectional(["R","AL"])) assert set(table.keys()) == RandAL -print """ +print(""" def in_table_d1(code): return unicodedata.bidirectional(code) in ("R","AL") -""" +""") # D.2 Characters with bidirectional property "L" name, table = tables[0] @@ -419,7 +419,7 @@ assert name == "D.2" L = set(gen_bidirectional(["L"])) assert set(table.keys()) == L -print """ +print(""" def in_table_d2(code): return unicodedata.bidirectional(code) == "L" -""" +""") |
