summaryrefslogtreecommitdiffstats
path: root/Tools
diff options
context:
space:
mode:
authorFlorent Xicluna <florent.xicluna@gmail.com>2010-03-15 14:00:58 (GMT)
committerFlorent Xicluna <florent.xicluna@gmail.com>2010-03-15 14:00:58 (GMT)
commitdc36472472361d8a360d97adbc7f1a3a8fce4493 (patch)
tree87b5391ab358d04c20da1ad0f8fa990d1f3fe3c2 /Tools
parent358e7ff36b60ee933fbd913a8da9a9b55f8a90c9 (diff)
downloadcpython-dc36472472361d8a360d97adbc7f1a3a8fce4493.zip
cpython-dc36472472361d8a360d97adbc7f1a3a8fce4493.tar.gz
cpython-dc36472472361d8a360d97adbc7f1a3a8fce4493.tar.bz2
Remove py3k deprecation warnings from these Unicode tools.
Diffstat (limited to 'Tools')
-rw-r--r--Tools/unicode/gencodec.py19
-rw-r--r--Tools/unicode/makeunicodedata.py24
-rw-r--r--Tools/unicode/mkstringprep.py26
3 files changed, 27 insertions, 42 deletions
diff --git a/Tools/unicode/gencodec.py b/Tools/unicode/gencodec.py
index 431a76d..165c913 100644
--- a/Tools/unicode/gencodec.py
+++ b/Tools/unicode/gencodec.py
@@ -40,8 +40,7 @@ mapRE = re.compile('((?:0x[0-9a-fA-F]+\+?)+)'
'\s*'
'(#.+)?')
-def parsecodes(codes,
- len=len, filter=filter,range=range):
+def parsecodes(codes, len=len, range=range):
""" Converts code combinations to either a single code integer
or a tuple of integers.
@@ -62,7 +61,7 @@ def parsecodes(codes,
l[i] = int(l[i],16)
except ValueError:
l[i] = None
- l = filter(lambda x: x is not None, l)
+ l = [x for x in l if x is not None]
if len(l) == 1:
return l[0]
else:
@@ -138,7 +137,7 @@ def python_mapdef_code(varname, map, comments=1, precisions=(2, 4)):
l = []
append = l.append
- if map.has_key("IDENTITY"):
+ if "IDENTITY" in map:
append("%s = codecs.make_identity_dict(range(%d))" %
(varname, map["IDENTITY"]))
append("%s.update({" % varname)
@@ -150,8 +149,7 @@ def python_mapdef_code(varname, map, comments=1, precisions=(2, 4)):
splits = 0
identity = 0
- mappings = map.items()
- mappings.sort()
+ mappings = sorted(map.items())
i = 0
key_precision, value_precision = precisions
for mapkey, mapvalue in mappings:
@@ -199,11 +197,10 @@ def python_tabledef_code(varname, map, comments=1, key_precision=2):
append('%s = (' % varname)
# Analyze map and create table dict
- mappings = map.items()
- mappings.sort()
+ mappings = sorted(map.items())
table = {}
maxkey = 0
- if map.has_key('IDENTITY'):
+ if 'IDENTITY' in map:
for key in range(256):
table[key] = (key, '')
maxkey = 255
@@ -421,6 +418,6 @@ if __name__ == '__main__':
import sys
if 1:
- apply(convertdir,tuple(sys.argv[1:]))
+ convertdir(*sys.argv[1:])
else:
- apply(rewritepythondir,tuple(sys.argv[1:]))
+ rewritepythondir(*sys.argv[1:])
diff --git a/Tools/unicode/makeunicodedata.py b/Tools/unicode/makeunicodedata.py
index 330eb2d..0bcc2e9 100644
--- a/Tools/unicode/makeunicodedata.py
+++ b/Tools/unicode/makeunicodedata.py
@@ -156,8 +156,7 @@ def makeunicodedata(unicode, trace):
prefix = i
assert prefix < 256
# content
- decomp = [prefix + (len(decomp)<<8)] +\
- map(lambda s: int(s, 16), decomp)
+ decomp = [prefix + (len(decomp)<<8)] + [int(s, 16) for s in decomp]
# Collect NFC pairs
if not prefix and len(decomp) == 3 and \
char not in unicode.exclusions and \
@@ -459,8 +458,7 @@ def makeunicodetype(unicode, trace):
Array("index2", index2).dump(fp, trace)
# Generate code for _PyUnicode_ToNumeric()
- numeric_items = numeric.items()
- numeric_items.sort()
+ numeric_items = sorted(numeric.items())
print >>fp, '/* Returns the numeric value as double for Unicode characters'
print >>fp, ' * having this property, -1.0 otherwise.'
print >>fp, ' */'
@@ -506,8 +504,7 @@ def makeunicodetype(unicode, trace):
haswide = False
hasnonewide = False
- spaces.sort()
- for codepoint in spaces:
+ for codepoint in sorted(spaces):
if codepoint < 0x10000:
hasnonewide = True
if codepoint >= 0x10000 and not haswide:
@@ -535,8 +532,7 @@ def makeunicodetype(unicode, trace):
print >>fp, ' switch (ch) {'
haswide = False
hasnonewide = False
- linebreaks.sort()
- for codepoint in linebreaks:
+ for codepoint in sorted(linebreaks):
if codepoint < 0x10000:
hasnonewide = True
if codepoint >= 0x10000 and not haswide:
@@ -601,12 +597,10 @@ def makeunicodename(unicode, trace):
wordlist = words.items()
# sort on falling frequency, then by name
- def cmpwords((aword, alist),(bword, blist)):
- r = -cmp(len(alist),len(blist))
- if r:
- return r
- return cmp(aword, bword)
- wordlist.sort(cmpwords)
+ def word_key(a):
+ aword, alist = a
+ return -len(alist), aword
+ wordlist.sort(key=word_key)
# figure out how many phrasebook escapes we need
escapes = 0
@@ -630,7 +624,7 @@ def makeunicodename(unicode, trace):
# length (to maximize overlap)
wordlist, wordtail = wordlist[:short], wordlist[short:]
- wordtail.sort(lambda a, b: len(b[0])-len(a[0]))
+ wordtail.sort(key=lambda a: a[0], reverse=True)
wordlist.extend(wordtail)
# generate lexicon from words
diff --git a/Tools/unicode/mkstringprep.py b/Tools/unicode/mkstringprep.py
index 2525f9e..99fcae7 100644
--- a/Tools/unicode/mkstringprep.py
+++ b/Tools/unicode/mkstringprep.py
@@ -1,7 +1,7 @@
import re, unicodedata, sys
if sys.maxunicode == 65535:
- raise RuntimeError, "need UCS-4 Python"
+ raise RuntimeError("need UCS-4 Python")
def gen_category(cats):
for i in range(0, 0x110000):
@@ -63,14 +63,14 @@ for l in data:
if m:
if m.group(1) == "Start":
if curname:
- raise "Double Start",(curname, l)
+ raise RuntimeError("Double Start", (curname, l))
curname = m.group(2)
table = {}
tables.append((curname, table))
continue
else:
if not curname:
- raise "End without start", l
+ raise RuntimeError("End without start", l)
curname = None
continue
if not curname:
@@ -87,7 +87,7 @@ for l in data:
try:
start, end = fields
except ValueError:
- raise "Unpacking problem", l
+ raise RuntimeError("Unpacking problem", l)
else:
start = end = fields[0]
start = int(start, 16)
@@ -146,8 +146,7 @@ def in_table_a1(code):
name, table = tables[0]
del tables[0]
assert name == "B.1"
-table = table.keys()
-table.sort()
+table = sorted(table.keys())
print """
b1_set = """ + compact_set(table) + """
def in_table_b1(code):
@@ -177,8 +176,7 @@ for k,v in table_b2.items():
if map(ord, unichr(k).lower()) != v:
b3_exceptions[k] = u"".join(map(unichr,v))
-b3 = b3_exceptions.items()
-b3.sort()
+b3 = sorted(b3_exceptions.items())
print """
b3_exceptions = {"""
@@ -353,8 +351,7 @@ name, table = tables[0]
del tables[0]
assert name == "C.6"
-table = table.keys()
-table.sort()
+table = sorted(table.keys())
print """
c6_set = """ + compact_set(table) + """
@@ -367,8 +364,7 @@ name, table = tables[0]
del tables[0]
assert name == "C.7"
-table = table.keys()
-table.sort()
+table = sorted(table.keys())
print """
c7_set = """ + compact_set(table) + """
@@ -381,8 +377,7 @@ name, table = tables[0]
del tables[0]
assert name == "C.8"
-table = table.keys()
-table.sort()
+table = sorted(table.keys())
print """
c8_set = """ + compact_set(table) + """
@@ -395,8 +390,7 @@ name, table = tables[0]
del tables[0]
assert name == "C.9"
-table = table.keys()
-table.sort()
+table = sorted(table.keys())
print """
c9_set = """ + compact_set(table) + """