Actual py3 compatibility making on gen-* scripts (#941)

This commit is contained in:
Ebrahim Byagowi 2018-03-29 21:22:47 +04:30 committed by GitHub
parent cab2c2c08c
commit 26e0cbd834
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 18 additions and 17 deletions

View File

@ -9,7 +9,7 @@ if len (sys.argv) != 4:
print ("usage: ./gen-arabic-table.py ArabicShaping.txt UnicodeData.txt Blocks.txt", file=sys.stderr) print ("usage: ./gen-arabic-table.py ArabicShaping.txt UnicodeData.txt Blocks.txt", file=sys.stderr)
sys.exit (1) sys.exit (1)
files = [file (x) for x in sys.argv[1:]] files = [open (x) for x in sys.argv[1:]]
headers = [[files[0].readline (), files[0].readline ()], [files[2].readline (), files[2].readline ()]] headers = [[files[0].readline (), files[0].readline ()], [files[2].readline (), files[2].readline ()]]
headers.append (["UnicodeData.txt does not have a header."]) headers.append (["UnicodeData.txt does not have a header."])
@ -229,9 +229,7 @@ def print_shaping_table(f):
print (" } ligatures[%d];" % max_i) print (" } ligatures[%d];" % max_i)
print ("} ligature_table[] =") print ("} ligature_table[] =")
print ("{") print ("{")
keys = ligas.keys () for first in sorted (ligas.keys ()):
keys.sort ()
for first in keys:
print (" { 0x%04Xu, {" % (first)) print (" { 0x%04Xu, {" % (first))
for liga in ligas[first]: for liga in ligas[first]:

View File

@ -32,7 +32,7 @@ ALLOWED_BLOCKS = [
'Myanmar Extended-A', 'Myanmar Extended-A',
] ]
files = [file (x) for x in sys.argv[1:]] files = [open (x) for x in sys.argv[1:]]
headers = [[f.readline () for i in range (2)] for f in files] headers = [[f.readline () for i in range (2)] for f in files]
@ -133,8 +133,7 @@ what = ["INDIC_SYLLABIC_CATEGORY", "INDIC_MATRA_CATEGORY"]
what_short = ["ISC", "IMC"] what_short = ["ISC", "IMC"]
for i in range (2): for i in range (2):
print () print ()
vv = values[i].keys () vv = sorted (values[i].keys ())
vv.sort ()
for v in vv: for v in vv:
v_no_and = v.replace ('_And_', '_') v_no_and = v.replace ('_And_', '_')
if v in short[i]: if v in short[i]:
@ -180,8 +179,7 @@ def print_block (block, start, end, data):
if block: if block:
last_block = block last_block = block
uu = data.keys () uu = sorted (data.keys ())
uu.sort ()
last = -100000 last = -100000
num = 0 num = 0
@ -228,7 +226,7 @@ print ("hb_indic_get_categories (hb_codepoint_t u)")
print ("{") print ("{")
print (" switch (u >> %d)" % page_bits) print (" switch (u >> %d)" % page_bits)
print (" {") print (" {")
pages = set([u>>page_bits for u in starts+ends+singles.keys()]) pages = set ([u>>page_bits for u in starts+ends+list (singles.keys ())])
for p in sorted(pages): for p in sorted(pages):
print (" case 0x%0Xu:" % p) print (" case 0x%0Xu:" % p)
for u,d in singles.items (): for u,d in singles.items ():
@ -249,8 +247,7 @@ print ()
print ("#undef _") print ("#undef _")
for i in range (2): for i in range (2):
print print
vv = values[i].keys () vv = sorted (values[i].keys ())
vv.sort ()
for v in vv: for v in vv:
print ("#undef %s_%s" % print ("#undef %s_%s" %
(what_short[i], short[i][v])) (what_short[i], short[i][v]))

View File

@ -10,7 +10,7 @@ if len (sys.argv) != 5:
BLACKLISTED_BLOCKS = ["Thai", "Lao", "Tibetan"] BLACKLISTED_BLOCKS = ["Thai", "Lao", "Tibetan"]
files = [file (x) for x in sys.argv[1:]] files = [open (x) for x in sys.argv[1:]]
headers = [[f.readline () for i in range (2)] for j,f in enumerate(files) if j != 2] headers = [[f.readline () for i in range (2)] for j,f in enumerate(files) if j != 2]
headers.append (["UnicodeData.txt does not have a header."]) headers.append (["UnicodeData.txt does not have a header."])
@ -126,6 +126,11 @@ property_names = [
'Overstruck', 'Overstruck',
] ]
try:
basestring
except NameError:
basestring = str
class PropertyValue(object): class PropertyValue(object):
def __init__(self, name_): def __init__(self, name_):
self.name = name_ self.name = name_
@ -135,6 +140,8 @@ class PropertyValue(object):
return self.name == (other if isinstance(other, basestring) else other.name) return self.name == (other if isinstance(other, basestring) else other.name)
def __ne__(self, other): def __ne__(self, other):
return not (self == other) return not (self == other)
def __hash__(self):
return hash(str(self))
property_values = {} property_values = {}
@ -398,8 +405,7 @@ def print_block (block, start, end, data):
if block: if block:
last_block = block last_block = block
uu = data.keys () uu = sorted (data.keys ())
uu.sort ()
last = -100000 last = -100000
num = 0 num = 0

View File

@ -514,7 +514,7 @@ class FileHelpers:
def open_file_or_stdin (f): def open_file_or_stdin (f):
if f == '-': if f == '-':
return sys.stdin return sys.stdin
return file (f) return open (f)
class Manifest: class Manifest:
@ -533,7 +533,7 @@ class Manifest:
if os.path.isdir (s): if os.path.isdir (s):
try: try:
m = file (os.path.join (s, "MANIFEST")) m = open (os.path.join (s, "MANIFEST"))
items = [x.strip () for x in m.readlines ()] items = [x.strip () for x in m.readlines ()]
for f in items: for f in items:
for p in Manifest.read (os.path.join (s, f)): for p in Manifest.read (os.path.join (s, f)):