Convert print statements to function calls in Tools/.

This commit is contained in:
Collin Winter 2007-08-03 17:06:41 +00:00
parent e5d0e8431f
commit 6afaeb757a
66 changed files with 777 additions and 779 deletions

View file

@ -11,7 +11,7 @@ import sys
def compare_codecs(encoding1, encoding2):
print 'Comparing encoding/decoding of %r and %r' % (encoding1, encoding2)
print('Comparing encoding/decoding of %r and %r' % (encoding1, encoding2))
mismatch = 0
# Check encoding
for i in range(sys.maxunicode):
@ -25,8 +25,8 @@ def compare_codecs(encoding1, encoding2):
except UnicodeError as reason:
c2 = '<undefined>'
if c1 != c2:
print ' * encoding mismatch for 0x%04X: %-14r != %r' % \
(i, c1, c2)
print(' * encoding mismatch for 0x%04X: %-14r != %r' % \
(i, c1, c2))
mismatch += 1
# Check decoding
for i in range(256):
@ -40,14 +40,14 @@ def compare_codecs(encoding1, encoding2):
except UnicodeError:
u2 = u'<undefined>'
if u1 != u2:
print ' * decoding mismatch for 0x%04X: %-14r != %r' % \
(i, u1, u2)
print(' * decoding mismatch for 0x%04X: %-14r != %r' % \
(i, u1, u2))
mismatch += 1
if mismatch:
print
print 'Found %i mismatches' % mismatch
print()
print('Found %i mismatches' % mismatch)
else:
print '-> Codecs are identical.'
print('-> Codecs are identical.')
if __name__ == '__main__':
compare_codecs(sys.argv[1], sys.argv[2])

View file

@ -131,7 +131,7 @@ def hexrepr(t, precision=4):
return '(' + ', '.join(['0x%0*X' % (precision, item)
for item in t]) + ')'
except TypeError as why:
print '* failed to convert %r: %s' % (t, why)
print('* failed to convert %r: %s' % (t, why))
raise
def python_mapdef_code(varname, map, comments=1, precisions=(2, 4)):
@ -383,18 +383,18 @@ def convertdir(dir, dirprefix='', nameprefix='', comments=1):
name = nameprefix + name
codefile = name + '.py'
marshalfile = name + '.mapping'
print 'converting %s to %s and %s' % (mapname,
print('converting %s to %s and %s' % (mapname,
dirprefix + codefile,
dirprefix + marshalfile)
dirprefix + marshalfile))
try:
map = readmap(os.path.join(dir,mapname))
if not map:
print '* map is empty; skipping'
print('* map is empty; skipping')
else:
pymap(mappathname, map, dirprefix + codefile,name,comments)
marshalmap(mappathname, map, dirprefix + marshalfile)
except ValueError as why:
print '* conversion failed: %s' % why
print('* conversion failed: %s' % why)
raise
def rewritepythondir(dir, dirprefix='', comments=1):
@ -405,17 +405,17 @@ def rewritepythondir(dir, dirprefix='', comments=1):
continue
name = mapname[:-len('.mapping')]
codefile = name + '.py'
print 'converting %s to %s' % (mapname,
dirprefix + codefile)
print('converting %s to %s' % (mapname,
dirprefix + codefile))
try:
map = marshal.load(open(os.path.join(dir,mapname),
'rb'))
if not map:
print '* map is empty; skipping'
print('* map is empty; skipping')
else:
pymap(mapname, map, dirprefix + codefile,name,comments)
except ValueError as why:
print '* conversion failed: %s' % why
print('* conversion failed: %s' % why)
if __name__ == '__main__':

View file

@ -26,8 +26,8 @@ def listcodecs(dir):
# Probably an error from importing the codec; still it's
# a valid code name
if _debug:
print '* problem importing codec %r: %s' % \
(name, reason)
print('* problem importing codec %r: %s' % \
(name, reason))
names.append(name)
return names
@ -35,7 +35,7 @@ def listcodecs(dir):
if __name__ == '__main__':
names = listcodecs(encodings.__path__[0])
names.sort()
print 'all_codecs = ['
print('all_codecs = [')
for name in names:
print ' %r,' % name
print ']'
print(' %r,' % name)
print(']')

View file

@ -60,21 +60,21 @@ UPPER_MASK = 0x80
def maketables(trace=0):
print "--- Reading", UNICODE_DATA % "", "..."
print("--- Reading", UNICODE_DATA % "", "...")
version = ""
unicode = UnicodeData(UNICODE_DATA % version,
COMPOSITION_EXCLUSIONS % version,
EASTASIAN_WIDTH % version)
print len(filter(None, unicode.table)), "characters"
print(len(filter(None, unicode.table)), "characters")
for version in old_versions:
print "--- Reading", UNICODE_DATA % ("-"+version), "..."
print("--- Reading", UNICODE_DATA % ("-"+version), "...")
old_unicode = UnicodeData(UNICODE_DATA % ("-"+version),
COMPOSITION_EXCLUSIONS % ("-"+version),
EASTASIAN_WIDTH % ("-"+version))
print len(filter(None, old_unicode.table)), "characters"
print(len(filter(None, old_unicode.table)), "characters")
merge_old_version(version, unicode, old_unicode)
makeunicodename(unicode, trace)
@ -93,7 +93,7 @@ def makeunicodedata(unicode, trace):
FILE = "Modules/unicodedata_db.h"
print "--- Preparing", FILE, "..."
print("--- Preparing", FILE, "...")
# 1) database properties
@ -203,93 +203,92 @@ def makeunicodedata(unicode, trace):
l = comp_last[l]
comp_data[f*total_last+l] = char
print len(table), "unique properties"
print len(decomp_prefix), "unique decomposition prefixes"
print len(decomp_data), "unique decomposition entries:",
print decomp_size, "bytes"
print total_first, "first characters in NFC"
print total_last, "last characters in NFC"
print len(comp_pairs), "NFC pairs"
print(len(table), "unique properties")
print(len(decomp_prefix), "unique decomposition prefixes")
print(len(decomp_data), "unique decomposition entries:", end=' ')
print(decomp_size, "bytes")
print(total_first, "first characters in NFC")
print(total_last, "last characters in NFC")
print(len(comp_pairs), "NFC pairs")
print "--- Writing", FILE, "..."
print("--- Writing", FILE, "...")
fp = open(FILE, "w")
print >>fp, "/* this file was generated by %s %s */" % (SCRIPT, VERSION)
print >>fp
print >>fp, '#define UNIDATA_VERSION "%s"' % UNIDATA_VERSION
print >>fp, "/* a list of unique database records */"
print >>fp, \
"const _PyUnicode_DatabaseRecord _PyUnicode_Database_Records[] = {"
print("/* this file was generated by %s %s */" % (SCRIPT, VERSION), file=fp)
print(file=fp)
print('#define UNIDATA_VERSION "%s"' % UNIDATA_VERSION, file=fp)
print("/* a list of unique database records */", file=fp)
print("const _PyUnicode_DatabaseRecord _PyUnicode_Database_Records[] = {", file=fp)
for item in table:
print >>fp, " {%d, %d, %d, %d, %d}," % item
print >>fp, "};"
print >>fp
print(" {%d, %d, %d, %d, %d}," % item, file=fp)
print("};", file=fp)
print(file=fp)
print >>fp, "/* Reindexing of NFC first characters. */"
print >>fp, "#define TOTAL_FIRST",total_first
print >>fp, "#define TOTAL_LAST",total_last
print >>fp, "struct reindex{int start;short count,index;};"
print >>fp, "struct reindex nfc_first[] = {"
print("/* Reindexing of NFC first characters. */", file=fp)
print("#define TOTAL_FIRST",total_first, file=fp)
print("#define TOTAL_LAST",total_last, file=fp)
print("struct reindex{int start;short count,index;};", file=fp)
print("struct reindex nfc_first[] = {", file=fp)
for start,end in comp_first_ranges:
print >>fp," { %d, %d, %d}," % (start,end-start,comp_first[start])
print >>fp," {0,0,0}"
print >>fp,"};\n"
print >>fp, "struct reindex nfc_last[] = {"
print(" { %d, %d, %d}," % (start,end-start,comp_first[start]), file=fp)
print(" {0,0,0}", file=fp)
print("};\n", file=fp)
print("struct reindex nfc_last[] = {", file=fp)
for start,end in comp_last_ranges:
print >>fp," { %d, %d, %d}," % (start,end-start,comp_last[start])
print >>fp," {0,0,0}"
print >>fp,"};\n"
print(" { %d, %d, %d}," % (start,end-start,comp_last[start]), file=fp)
print(" {0,0,0}", file=fp)
print("};\n", file=fp)
# FIXME: <fl> the following tables could be made static, and
# the support code moved into unicodedatabase.c
print >>fp, "/* string literals */"
print >>fp, "const char *_PyUnicode_CategoryNames[] = {"
print("/* string literals */", file=fp)
print("const char *_PyUnicode_CategoryNames[] = {", file=fp)
for name in CATEGORY_NAMES:
print >>fp, " \"%s\"," % name
print >>fp, " NULL"
print >>fp, "};"
print(" \"%s\"," % name, file=fp)
print(" NULL", file=fp)
print("};", file=fp)
print >>fp, "const char *_PyUnicode_BidirectionalNames[] = {"
print("const char *_PyUnicode_BidirectionalNames[] = {", file=fp)
for name in BIDIRECTIONAL_NAMES:
print >>fp, " \"%s\"," % name
print >>fp, " NULL"
print >>fp, "};"
print(" \"%s\"," % name, file=fp)
print(" NULL", file=fp)
print("};", file=fp)
print >>fp, "const char *_PyUnicode_EastAsianWidthNames[] = {"
print("const char *_PyUnicode_EastAsianWidthNames[] = {", file=fp)
for name in EASTASIANWIDTH_NAMES:
print >>fp, " \"%s\"," % name
print >>fp, " NULL"
print >>fp, "};"
print(" \"%s\"," % name, file=fp)
print(" NULL", file=fp)
print("};", file=fp)
print >>fp, "static const char *decomp_prefix[] = {"
print("static const char *decomp_prefix[] = {", file=fp)
for name in decomp_prefix:
print >>fp, " \"%s\"," % name
print >>fp, " NULL"
print >>fp, "};"
print(" \"%s\"," % name, file=fp)
print(" NULL", file=fp)
print("};", file=fp)
# split record index table
index1, index2, shift = splitbins(index, trace)
print >>fp, "/* index tables for the database records */"
print >>fp, "#define SHIFT", shift
print("/* index tables for the database records */", file=fp)
print("#define SHIFT", shift, file=fp)
Array("index1", index1).dump(fp, trace)
Array("index2", index2).dump(fp, trace)
# split decomposition index table
index1, index2, shift = splitbins(decomp_index, trace)
print >>fp, "/* decomposition data */"
print("/* decomposition data */", file=fp)
Array("decomp_data", decomp_data).dump(fp, trace)
print >>fp, "/* index tables for the decomposition data */"
print >>fp, "#define DECOMP_SHIFT", shift
print("/* index tables for the decomposition data */", file=fp)
print("#define DECOMP_SHIFT", shift, file=fp)
Array("decomp_index1", index1).dump(fp, trace)
Array("decomp_index2", index2).dump(fp, trace)
index, index2, shift = splitbins(comp_data, trace)
print >>fp, "/* NFC pairs */"
print >>fp, "#define COMP_SHIFT", shift
print("/* NFC pairs */", file=fp)
print("#define COMP_SHIFT", shift, file=fp)
Array("comp_index", index).dump(fp, trace)
Array("comp_data", index2).dump(fp, trace)
@ -306,30 +305,30 @@ def makeunicodedata(unicode, trace):
index[i] = cache[record] = len(records)
records.append(record)
index1, index2, shift = splitbins(index, trace)
print >>fp, "static const change_record change_records_%s[] = {" % cversion
print("static const change_record change_records_%s[] = {" % cversion, file=fp)
for record in records:
print >>fp, "\t{ %s }," % ", ".join(map(str,record))
print >>fp, "};"
print("\t{ %s }," % ", ".join(map(str,record)), file=fp)
print("};", file=fp)
Array("changes_%s_index" % cversion, index1).dump(fp, trace)
Array("changes_%s_data" % cversion, index2).dump(fp, trace)
print >>fp, "static const change_record* get_change_%s(Py_UCS4 n)" % cversion
print >>fp, "{"
print >>fp, "\tint index;"
print >>fp, "\tif (n >= 0x110000) index = 0;"
print >>fp, "\telse {"
print >>fp, "\t\tindex = changes_%s_index[n>>%d];" % (cversion, shift)
print >>fp, "\t\tindex = changes_%s_data[(index<<%d)+(n & %d)];" % \
(cversion, shift, ((1<<shift)-1))
print >>fp, "\t}"
print >>fp, "\treturn change_records_%s+index;" % cversion
print >>fp, "}\n"
print >>fp, "static Py_UCS4 normalization_%s(Py_UCS4 n)" % cversion
print >>fp, "{"
print >>fp, "\tswitch(n) {"
print("static const change_record* get_change_%s(Py_UCS4 n)" % cversion, file=fp)
print("{", file=fp)
print("\tint index;", file=fp)
print("\tif (n >= 0x110000) index = 0;", file=fp)
print("\telse {", file=fp)
print("\t\tindex = changes_%s_index[n>>%d];" % (cversion, shift), file=fp)
print("\t\tindex = changes_%s_data[(index<<%d)+(n & %d)];" % \
(cversion, shift, ((1<<shift)-1)), file=fp)
print("\t}", file=fp)
print("\treturn change_records_%s+index;" % cversion, file=fp)
print("}\n", file=fp)
print("static Py_UCS4 normalization_%s(Py_UCS4 n)" % cversion, file=fp)
print("{", file=fp)
print("\tswitch(n) {", file=fp)
for k, v in normalization:
print >>fp, "\tcase %s: return 0x%s;" % (hex(k), v)
print >>fp, "\tdefault: return 0;"
print >>fp, "\t}\n}\n"
print("\tcase %s: return 0x%s;" % (hex(k), v), file=fp)
print("\tdefault: return 0;", file=fp)
print("\t}\n}\n", file=fp)
fp.close()
@ -340,7 +339,7 @@ def makeunicodetype(unicode, trace):
FILE = "Objects/unicodetype_db.h"
print "--- Preparing", FILE, "..."
print("--- Preparing", FILE, "...")
# extract unicode types
dummy = (0, 0, 0, 0, 0, 0)
@ -405,25 +404,25 @@ def makeunicodetype(unicode, trace):
table.append(item)
index[char] = i
print len(table), "unique character type entries"
print(len(table), "unique character type entries")
print "--- Writing", FILE, "..."
print("--- Writing", FILE, "...")
fp = open(FILE, "w")
print >>fp, "/* this file was generated by %s %s */" % (SCRIPT, VERSION)
print >>fp
print >>fp, "/* a list of unique character type descriptors */"
print >>fp, "const _PyUnicode_TypeRecord _PyUnicode_TypeRecords[] = {"
print("/* this file was generated by %s %s */" % (SCRIPT, VERSION), file=fp)
print(file=fp)
print("/* a list of unique character type descriptors */", file=fp)
print("const _PyUnicode_TypeRecord _PyUnicode_TypeRecords[] = {", file=fp)
for item in table:
print >>fp, " {%d, %d, %d, %d, %d, %d}," % item
print >>fp, "};"
print >>fp
print(" {%d, %d, %d, %d, %d, %d}," % item, file=fp)
print("};", file=fp)
print(file=fp)
# split decomposition index table
index1, index2, shift = splitbins(index, trace)
print >>fp, "/* type indexes */"
print >>fp, "#define SHIFT", shift
print("/* type indexes */", file=fp)
print("#define SHIFT", shift, file=fp)
Array("index1", index1).dump(fp, trace)
Array("index2", index2).dump(fp, trace)
@ -436,7 +435,7 @@ def makeunicodename(unicode, trace):
FILE = "Modules/unicodename_db.h"
print "--- Preparing", FILE, "..."
print("--- Preparing", FILE, "...")
# collect names
names = [None] * len(unicode.chars)
@ -448,7 +447,7 @@ def makeunicodename(unicode, trace):
if name and name[0] != "<":
names[char] = name + chr(0)
print len(filter(lambda n: n is not None, names)), "distinct names"
print(len(filter(lambda n: n is not None, names)), "distinct names")
# collect unique words from names (note that we differ between
# words inside a sentence, and words ending a sentence. the
@ -469,7 +468,7 @@ def makeunicodename(unicode, trace):
else:
words[w] = [len(words)]
print n, "words in text;", b, "bytes"
print(n, "words in text;", b, "bytes")
wordlist = words.items()
@ -485,19 +484,19 @@ def makeunicodename(unicode, trace):
escapes = 0
while escapes * 256 < len(wordlist):
escapes = escapes + 1
print escapes, "escapes"
print(escapes, "escapes")
short = 256 - escapes
assert short > 0
print short, "short indexes in lexicon"
print(short, "short indexes in lexicon")
# statistics
n = 0
for i in range(short):
n = n + len(wordlist[i][1])
print n, "short indexes in phrasebook"
print(n, "short indexes in phrasebook")
# pick the most commonly used words, and sort the rest on falling
# length (to maximize overlap)
@ -566,29 +565,29 @@ def makeunicodename(unicode, trace):
codehash = Hash("code", data, 47)
print "--- Writing", FILE, "..."
print("--- Writing", FILE, "...")
fp = open(FILE, "w")
print >>fp, "/* this file was generated by %s %s */" % (SCRIPT, VERSION)
print >>fp
print >>fp, "#define NAME_MAXLEN", 256
print >>fp
print >>fp, "/* lexicon */"
print("/* this file was generated by %s %s */" % (SCRIPT, VERSION), file=fp)
print(file=fp)
print("#define NAME_MAXLEN", 256, file=fp)
print(file=fp)
print("/* lexicon */", file=fp)
Array("lexicon", lexicon).dump(fp, trace)
Array("lexicon_offset", lexicon_offset).dump(fp, trace)
# split decomposition index table
offset1, offset2, shift = splitbins(phrasebook_offset, trace)
print >>fp, "/* code->name phrasebook */"
print >>fp, "#define phrasebook_shift", shift
print >>fp, "#define phrasebook_short", short
print("/* code->name phrasebook */", file=fp)
print("#define phrasebook_shift", shift, file=fp)
print("#define phrasebook_short", short, file=fp)
Array("phrasebook", phrasebook).dump(fp, trace)
Array("phrasebook_offset1", offset1).dump(fp, trace)
Array("phrasebook_offset2", offset2).dump(fp, trace)
print >>fp, "/* name->code dictionary */"
print("/* name->code dictionary */", file=fp)
codehash.dump(fp, trace)
fp.close()
@ -781,7 +780,7 @@ class Hash:
else:
raise AssertionError, "ran out of polynominals"
print size, "slots in hash table"
print(size, "slots in hash table")
table = [None] * size
@ -813,7 +812,7 @@ class Hash:
if incr > mask:
incr = incr ^ poly
print n, "collisions"
print(n, "collisions")
self.collisions = n
for i in range(len(table)):
@ -845,7 +844,7 @@ class Array:
# write data to file, as a C array
size = getsize(self.data)
if trace:
print >>sys.stderr, self.name+":", size*len(self.data), "bytes"
print(self.name+":", size*len(self.data), "bytes", file=sys.stderr)
file.write("static ")
if size == 1:
file.write("unsigned char")
@ -895,10 +894,10 @@ def splitbins(t, trace=0):
import sys
if trace:
def dump(t1, t2, shift, bytes):
print >>sys.stderr, "%d+%d bins at shift %d; %d bytes" % (
len(t1), len(t2), shift, bytes)
print >>sys.stderr, "Size of original table:", len(t)*getsize(t), \
"bytes"
print("%d+%d bins at shift %d; %d bytes" % (
len(t1), len(t2), shift, bytes), file=sys.stderr)
print("Size of original table:", len(t)*getsize(t), \
"bytes", file=sys.stderr)
n = len(t)-1 # last valid index
maxshift = 0 # the most we can shift n and still have something left
if n > 0:
@ -930,7 +929,7 @@ def splitbins(t, trace=0):
bytes = b
t1, t2, shift = best
if trace:
print >>sys.stderr, "Best:",
print("Best:", end=' ', file=sys.stderr)
dump(t1, t2, shift, bytes)
if __debug__:
# exhaustively verify that the decomposition is correct

View file

@ -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,13 +134,13 @@ 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]
@ -148,11 +148,11 @@ del tables[0]
assert name == "B.1"
table = table.keys()
table.sort()
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
@ -180,20 +180,20 @@ for k,v in table_b2.items():
b3 = b3_exceptions.items()
b3.sort()
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))
@ -222,7 +222,7 @@ for k,v in table_b2.items():
# 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)
@ -232,7 +232,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]
@ -240,10 +240,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]
@ -254,13 +254,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]
@ -272,10 +272,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.
@ -290,7 +290,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
@ -300,7 +300,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]
@ -310,10 +310,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
@ -327,13 +327,13 @@ nonchar = set(range(0xFDD0,0xFDF0) +
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]
@ -343,10 +343,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]
@ -356,11 +356,11 @@ assert name == "C.6"
table = table.keys()
table.sort()
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]
@ -370,11 +370,11 @@ assert name == "C.7"
table = table.keys()
table.sort()
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]
@ -384,11 +384,11 @@ assert name == "C.8"
table = table.keys()
table.sort()
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]
@ -398,11 +398,11 @@ assert name == "C.9"
table = table.keys()
table.sort()
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]
@ -412,10 +412,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]
@ -425,7 +425,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"
"""
""")