Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
dc364724
Commit
dc364724
authored
Mar 15, 2010
by
Florent Xicluna
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove py3k deprecation warnings from these Unicode tools.
parent
358e7ff3
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
27 additions
and
42 deletions
+27
-42
Tools/unicode/gencodec.py
Tools/unicode/gencodec.py
+8
-11
Tools/unicode/makeunicodedata.py
Tools/unicode/makeunicodedata.py
+9
-15
Tools/unicode/mkstringprep.py
Tools/unicode/mkstringprep.py
+10
-16
No files found.
Tools/unicode/gencodec.py
View file @
dc364724
...
@@ -40,8 +40,7 @@ mapRE = re.compile('((?:0x[0-9a-fA-F]+\+?)+)'
...
@@ -40,8 +40,7 @@ mapRE = re.compile('((?:0x[0-9a-fA-F]+\+?)+)'
'
\
s
*
'
'
\
s
*
'
'
(
#.+)?')
'
(
#.+)?')
def
parsecodes
(
codes
,
def
parsecodes
(
codes
,
len
=
len
,
range
=
range
):
len
=
len
,
filter
=
filter
,
range
=
range
):
""" Converts code combinations to either a single code integer
""" Converts code combinations to either a single code integer
or a tuple of integers.
or a tuple of integers.
...
@@ -62,7 +61,7 @@ def parsecodes(codes,
...
@@ -62,7 +61,7 @@ def parsecodes(codes,
l
[
i
]
=
int
(
l
[
i
],
16
)
l
[
i
]
=
int
(
l
[
i
],
16
)
except
ValueError
:
except
ValueError
:
l
[
i
]
=
None
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
:
if
len
(
l
)
==
1
:
return
l
[
0
]
return
l
[
0
]
else
:
else
:
...
@@ -138,7 +137,7 @@ def python_mapdef_code(varname, map, comments=1, precisions=(2, 4)):
...
@@ -138,7 +137,7 @@ def python_mapdef_code(varname, map, comments=1, precisions=(2, 4)):
l
=
[]
l
=
[]
append
=
l
.
append
append
=
l
.
append
if
map
.
has_key
(
"IDENTITY"
)
:
if
"IDENTITY"
in
map
:
append
(
"%s = codecs.make_identity_dict(range(%d))"
%
append
(
"%s = codecs.make_identity_dict(range(%d))"
%
(
varname
,
map
[
"IDENTITY"
]))
(
varname
,
map
[
"IDENTITY"
]))
append
(
"%s.update({"
%
varname
)
append
(
"%s.update({"
%
varname
)
...
@@ -150,8 +149,7 @@ def python_mapdef_code(varname, map, comments=1, precisions=(2, 4)):
...
@@ -150,8 +149,7 @@ def python_mapdef_code(varname, map, comments=1, precisions=(2, 4)):
splits
=
0
splits
=
0
identity
=
0
identity
=
0
mappings
=
map
.
items
()
mappings
=
sorted
(
map
.
items
())
mappings
.
sort
()
i
=
0
i
=
0
key_precision
,
value_precision
=
precisions
key_precision
,
value_precision
=
precisions
for
mapkey
,
mapvalue
in
mappings
:
for
mapkey
,
mapvalue
in
mappings
:
...
@@ -199,11 +197,10 @@ def python_tabledef_code(varname, map, comments=1, key_precision=2):
...
@@ -199,11 +197,10 @@ def python_tabledef_code(varname, map, comments=1, key_precision=2):
append
(
'%s = ('
%
varname
)
append
(
'%s = ('
%
varname
)
# Analyze map and create table dict
# Analyze map and create table dict
mappings
=
map
.
items
()
mappings
=
sorted
(
map
.
items
())
mappings
.
sort
()
table
=
{}
table
=
{}
maxkey
=
0
maxkey
=
0
if
map
.
has_key
(
'IDENTITY'
)
:
if
'IDENTITY'
in
map
:
for
key
in
range
(
256
):
for
key
in
range
(
256
):
table
[
key
]
=
(
key
,
''
)
table
[
key
]
=
(
key
,
''
)
maxkey
=
255
maxkey
=
255
...
@@ -421,6 +418,6 @@ if __name__ == '__main__':
...
@@ -421,6 +418,6 @@ if __name__ == '__main__':
import
sys
import
sys
if
1
:
if
1
:
apply
(
convertdir
,
tuple
(
sys
.
argv
[
1
:])
)
convertdir
(
*
sys
.
argv
[
1
:]
)
else
:
else
:
apply
(
rewritepythondir
,
tuple
(
sys
.
argv
[
1
:])
)
rewritepythondir
(
*
sys
.
argv
[
1
:]
)
Tools/unicode/makeunicodedata.py
View file @
dc364724
...
@@ -156,8 +156,7 @@ def makeunicodedata(unicode, trace):
...
@@ -156,8 +156,7 @@ def makeunicodedata(unicode, trace):
prefix
=
i
prefix
=
i
assert
prefix
<
256
assert
prefix
<
256
# content
# content
decomp
=
[
prefix
+
(
len
(
decomp
)
<<
8
)]
+
\
decomp
=
[
prefix
+
(
len
(
decomp
)
<<
8
)]
+
[
int
(
s
,
16
)
for
s
in
decomp
]
map
(
lambda
s
:
int
(
s
,
16
),
decomp
)
# Collect NFC pairs
# Collect NFC pairs
if
not
prefix
and
len
(
decomp
)
==
3
and
\
if
not
prefix
and
len
(
decomp
)
==
3
and
\
char
not
in
unicode
.
exclusions
and
\
char
not
in
unicode
.
exclusions
and
\
...
@@ -459,8 +458,7 @@ def makeunicodetype(unicode, trace):
...
@@ -459,8 +458,7 @@ def makeunicodetype(unicode, trace):
Array
(
"index2"
,
index2
).
dump
(
fp
,
trace
)
Array
(
"index2"
,
index2
).
dump
(
fp
,
trace
)
# Generate code for _PyUnicode_ToNumeric()
# Generate code for _PyUnicode_ToNumeric()
numeric_items
=
numeric
.
items
()
numeric_items
=
sorted
(
numeric
.
items
())
numeric_items
.
sort
()
print
>>
fp
,
'/* Returns the numeric value as double for Unicode characters'
print
>>
fp
,
'/* Returns the numeric value as double for Unicode characters'
print
>>
fp
,
' * having this property, -1.0 otherwise.'
print
>>
fp
,
' * having this property, -1.0 otherwise.'
print
>>
fp
,
' */'
print
>>
fp
,
' */'
...
@@ -506,8 +504,7 @@ def makeunicodetype(unicode, trace):
...
@@ -506,8 +504,7 @@ def makeunicodetype(unicode, trace):
haswide
=
False
haswide
=
False
hasnonewide
=
False
hasnonewide
=
False
spaces
.
sort
()
for
codepoint
in
sorted
(
spaces
):
for
codepoint
in
spaces
:
if
codepoint
<
0x10000
:
if
codepoint
<
0x10000
:
hasnonewide
=
True
hasnonewide
=
True
if
codepoint
>=
0x10000
and
not
haswide
:
if
codepoint
>=
0x10000
and
not
haswide
:
...
@@ -535,8 +532,7 @@ def makeunicodetype(unicode, trace):
...
@@ -535,8 +532,7 @@ def makeunicodetype(unicode, trace):
print
>>
fp
,
' switch (ch) {'
print
>>
fp
,
' switch (ch) {'
haswide
=
False
haswide
=
False
hasnonewide
=
False
hasnonewide
=
False
linebreaks
.
sort
()
for
codepoint
in
sorted
(
linebreaks
):
for
codepoint
in
linebreaks
:
if
codepoint
<
0x10000
:
if
codepoint
<
0x10000
:
hasnonewide
=
True
hasnonewide
=
True
if
codepoint
>=
0x10000
and
not
haswide
:
if
codepoint
>=
0x10000
and
not
haswide
:
...
@@ -601,12 +597,10 @@ def makeunicodename(unicode, trace):
...
@@ -601,12 +597,10 @@ def makeunicodename(unicode, trace):
wordlist
=
words
.
items
()
wordlist
=
words
.
items
()
# sort on falling frequency, then by name
# sort on falling frequency, then by name
def
cmpwords
((
aword
,
alist
),(
bword
,
blist
)):
def
word_key
(
a
):
r
=
-
cmp
(
len
(
alist
),
len
(
blist
))
aword
,
alist
=
a
if
r
:
return
-
len
(
alist
),
aword
return
r
wordlist
.
sort
(
key
=
word_key
)
return
cmp
(
aword
,
bword
)
wordlist
.
sort
(
cmpwords
)
# figure out how many phrasebook escapes we need
# figure out how many phrasebook escapes we need
escapes
=
0
escapes
=
0
...
@@ -630,7 +624,7 @@ def makeunicodename(unicode, trace):
...
@@ -630,7 +624,7 @@ def makeunicodename(unicode, trace):
# length (to maximize overlap)
# length (to maximize overlap)
wordlist
,
wordtail
=
wordlist
[:
short
],
wordlist
[
short
:]
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
)
wordlist
.
extend
(
wordtail
)
# generate lexicon from words
# generate lexicon from words
...
...
Tools/unicode/mkstringprep.py
View file @
dc364724
import
re
,
unicodedata
,
sys
import
re
,
unicodedata
,
sys
if
sys
.
maxunicode
==
65535
:
if
sys
.
maxunicode
==
65535
:
raise
RuntimeError
,
"need UCS-4 Python"
raise
RuntimeError
(
"need UCS-4 Python"
)
def
gen_category
(
cats
):
def
gen_category
(
cats
):
for
i
in
range
(
0
,
0x110000
):
for
i
in
range
(
0
,
0x110000
):
...
@@ -63,14 +63,14 @@ for l in data:
...
@@ -63,14 +63,14 @@ for l in data:
if
m
:
if
m
:
if
m
.
group
(
1
)
==
"Start"
:
if
m
.
group
(
1
)
==
"Start"
:
if
curname
:
if
curname
:
raise
"Double Start"
,(
curname
,
l
)
raise
RuntimeError
(
"Double Start"
,
(
curname
,
l
)
)
curname
=
m
.
group
(
2
)
curname
=
m
.
group
(
2
)
table
=
{}
table
=
{}
tables
.
append
((
curname
,
table
))
tables
.
append
((
curname
,
table
))
continue
continue
else
:
else
:
if
not
curname
:
if
not
curname
:
raise
"End without start"
,
l
raise
RuntimeError
(
"End without start"
,
l
)
curname
=
None
curname
=
None
continue
continue
if
not
curname
:
if
not
curname
:
...
@@ -87,7 +87,7 @@ for l in data:
...
@@ -87,7 +87,7 @@ for l in data:
try
:
try
:
start
,
end
=
fields
start
,
end
=
fields
except
ValueError
:
except
ValueError
:
raise
"Unpacking problem"
,
l
raise
RuntimeError
(
"Unpacking problem"
,
l
)
else
:
else
:
start
=
end
=
fields
[
0
]
start
=
end
=
fields
[
0
]
start
=
int
(
start
,
16
)
start
=
int
(
start
,
16
)
...
@@ -146,8 +146,7 @@ def in_table_a1(code):
...
@@ -146,8 +146,7 @@ def in_table_a1(code):
name
,
table
=
tables
[
0
]
name
,
table
=
tables
[
0
]
del
tables
[
0
]
del
tables
[
0
]
assert
name
==
"B.1"
assert
name
==
"B.1"
table
=
table
.
keys
()
table
=
sorted
(
table
.
keys
())
table
.
sort
()
print
"""
print
"""
b1_set = """
+
compact_set
(
table
)
+
"""
b1_set = """
+
compact_set
(
table
)
+
"""
def in_table_b1(code):
def in_table_b1(code):
...
@@ -177,8 +176,7 @@ for k,v in table_b2.items():
...
@@ -177,8 +176,7 @@ for k,v in table_b2.items():
if
map
(
ord
,
unichr
(
k
).
lower
())
!=
v
:
if
map
(
ord
,
unichr
(
k
).
lower
())
!=
v
:
b3_exceptions
[
k
]
=
u""
.
join
(
map
(
unichr
,
v
))
b3_exceptions
[
k
]
=
u""
.
join
(
map
(
unichr
,
v
))
b3
=
b3_exceptions
.
items
()
b3
=
sorted
(
b3_exceptions
.
items
())
b3
.
sort
()
print
"""
print
"""
b3_exceptions = {"""
b3_exceptions = {"""
...
@@ -353,8 +351,7 @@ name, table = tables[0]
...
@@ -353,8 +351,7 @@ name, table = tables[0]
del
tables
[
0
]
del
tables
[
0
]
assert
name
==
"C.6"
assert
name
==
"C.6"
table
=
table
.
keys
()
table
=
sorted
(
table
.
keys
())
table
.
sort
()
print
"""
print
"""
c6_set = """
+
compact_set
(
table
)
+
"""
c6_set = """
+
compact_set
(
table
)
+
"""
...
@@ -367,8 +364,7 @@ name, table = tables[0]
...
@@ -367,8 +364,7 @@ name, table = tables[0]
del
tables
[
0
]
del
tables
[
0
]
assert
name
==
"C.7"
assert
name
==
"C.7"
table
=
table
.
keys
()
table
=
sorted
(
table
.
keys
())
table
.
sort
()
print
"""
print
"""
c7_set = """
+
compact_set
(
table
)
+
"""
c7_set = """
+
compact_set
(
table
)
+
"""
...
@@ -381,8 +377,7 @@ name, table = tables[0]
...
@@ -381,8 +377,7 @@ name, table = tables[0]
del
tables
[
0
]
del
tables
[
0
]
assert
name
==
"C.8"
assert
name
==
"C.8"
table
=
table
.
keys
()
table
=
sorted
(
table
.
keys
())
table
.
sort
()
print
"""
print
"""
c8_set = """
+
compact_set
(
table
)
+
"""
c8_set = """
+
compact_set
(
table
)
+
"""
...
@@ -395,8 +390,7 @@ name, table = tables[0]
...
@@ -395,8 +390,7 @@ name, table = tables[0]
del
tables
[
0
]
del
tables
[
0
]
assert
name
==
"C.9"
assert
name
==
"C.9"
table
=
table
.
keys
()
table
=
sorted
(
table
.
keys
())
table
.
sort
()
print
"""
print
"""
c9_set = """
+
compact_set
(
table
)
+
"""
c9_set = """
+
compact_set
(
table
)
+
"""
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment