Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
bd20ea55
Kaydet (Commit)
bd20ea55
authored
Eki 25, 2005
tarafından
Marc-André Lemburg
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Apply some cosmetic fixes to the output of the script.
Only include the decoding map if no table can be generated.
üst
982e8d67
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
28 additions
and
15 deletions
+28
-15
gencodec.py
Tools/unicode/gencodec.py
+28
-15
No files found.
Tools/unicode/gencodec.py
Dosyayı görüntüle @
bd20ea55
...
...
@@ -15,12 +15,14 @@ lowercase with hyphens replaced by underscores.
The tool also writes marshalled versions of the mapping tables to the
same location (with .mapping extension).
Written by Marc-Andre Lemburg (mal@lemburg.com). Modified to generate
Unicode table maps for decoding.
Written by Marc-Andre Lemburg (mal@lemburg.com).
(c) Copyright CNRI, All Rights Reserved. NO WARRANTY.
(c) Copyright Guido van Rossum, 2000.
Table generation:
(c) Copyright Marc-Andre Lemburg, 2005.
Licensed to PSF under a Contributor Agreement.
"""
#"
...
...
@@ -117,21 +119,22 @@ def readmap(filename):
return
enc2uni
def
hexrepr
(
t
):
def
hexrepr
(
t
,
precision
=
4
):
if
t
is
None
:
return
'None'
try
:
len
(
t
)
except
:
return
'0x
%0
4
x'
%
t
return
'0x
%0
*
X'
%
(
precision
,
t
)
try
:
return
'('
+
', '
.
join
(
map
(
lambda
t
:
'0x
%04
x'
%
t
,
t
))
+
')'
return
'('
+
', '
.
join
([
'0x
%0*
X'
%
(
precision
,
item
)
for
item
in
t
])
+
')'
except
TypeError
,
why
:
print
'* failed to convert
%
r:
%
s'
%
(
t
,
why
)
raise
def
python_mapdef_code
(
varname
,
map
,
comments
=
1
):
def
python_mapdef_code
(
varname
,
map
,
comments
=
1
,
precisions
=
(
2
,
4
)
):
l
=
[]
append
=
l
.
append
...
...
@@ -150,6 +153,7 @@ def python_mapdef_code(varname, map, comments=1):
mappings
=
map
.
items
()
mappings
.
sort
()
i
=
0
key_precision
,
value_precision
=
precisions
for
mapkey
,
mapvalue
in
mappings
:
mapcomment
=
''
if
isinstance
(
mapkey
,
tuple
):
...
...
@@ -164,8 +168,8 @@ def python_mapdef_code(varname, map, comments=1):
# No need to include identity mappings, since these
# are already set for the first 256 code points.
continue
key
=
hexrepr
(
mapkey
)
value
=
hexrepr
(
mapvalue
)
key
=
hexrepr
(
mapkey
,
key_precision
)
value
=
hexrepr
(
mapvalue
,
value_precision
)
if
mapcomment
and
comments
:
append
(
'
%
s:
%
s,
\t
#
%
s'
%
(
key
,
value
,
mapcomment
))
else
:
...
...
@@ -188,7 +192,7 @@ def python_mapdef_code(varname, map, comments=1):
return
l
def
python_tabledef_code
(
varname
,
map
,
comments
=
1
):
def
python_tabledef_code
(
varname
,
map
,
comments
=
1
,
key_precision
=
2
):
l
=
[]
append
=
l
.
append
...
...
@@ -236,7 +240,7 @@ def python_tabledef_code(varname, map, comments=1):
mapchar
=
unichr
(
mapvalue
)
if
mapcomment
and
comments
:
append
(
'
%
r
\t
#
%
s ->
%
s'
%
(
mapchar
,
hexrepr
(
key
),
hexrepr
(
key
,
key_precision
),
mapcomment
))
else
:
append
(
'
%
r'
%
mapchar
)
...
...
@@ -263,7 +267,8 @@ def codegen(name, map, comments=1):
encoding_map_code
=
python_mapdef_code
(
'encoding_map'
,
codecs
.
make_encoding_map
(
map
),
comments
=
comments
)
comments
=
comments
,
precisions
=
(
4
,
2
))
l
=
[
'''
\
...
...
@@ -303,22 +308,28 @@ class StreamReader(Codec,codecs.StreamReader):
def getregentry():
return (Codec().encode,Codec().decode,StreamReader,StreamWriter)
'''
)
# Add decoding table or map (with preference to the table)
if
not
decoding_table_code
:
l
.
append
(
'''
### Decoding Map
'''
)
l
.
extend
(
decoding_map_code
)
# Add optional decoding table
if
decoding_table_code
:
l
.
extend
(
decoding_map_code
)
else
:
l
.
append
(
'''
### Decoding Table
'''
)
l
.
extend
(
decoding_table_code
)
# Add encoding map
l
.
append
(
'''
### Encoding Map
'''
)
l
.
extend
(
encoding_map_code
)
# Final new-line
l
.
append
(
'
\n
'
)
return
'
\n
'
.
join
(
l
)
...
...
@@ -343,6 +354,8 @@ def convertdir(dir,prefix='',comments=1):
mapnames
=
os
.
listdir
(
dir
)
for
mapname
in
mapnames
:
mappathname
=
os
.
path
.
join
(
dir
,
mapname
)
if
not
os
.
path
.
isfile
(
mappathname
):
continue
name
=
os
.
path
.
split
(
mapname
)[
1
]
name
=
name
.
replace
(
'-'
,
'_'
)
name
=
name
.
split
(
'.'
)[
0
]
...
...
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