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
172bb394
Unverified
Kaydet (Commit)
172bb394
authored
Mar 30, 2019
tarafından
Serhiy Storchaka
Kaydeden (comit)
GitHub
Mar 30, 2019
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
bpo-22831: Use "with" to avoid possible fd leaks in tools (part 2). (GH-10927)
üst
afbb7a37
Show whitespace changes
Inline
Side-by-side
Showing
27 changed files
with
63 additions
and
73 deletions
+63
-73
markov.py
Tools/demo/markov.py
+1
-1
rpython.py
Tools/demo/rpython.py
+1
-2
rpythond.py
Tools/demo/rpythond.py
+1
-1
checkextensions_win32.py
Tools/freeze/checkextensions_win32.py
+2
-1
freeze.py
Tools/freeze/freeze.py
+2
-1
pygettext.py
Tools/i18n/pygettext.py
+1
-2
cleanfuture.py
Tools/scripts/cleanfuture.py
+2
-3
combinerefs.py
Tools/scripts/combinerefs.py
+5
-4
dutree.py
Tools/scripts/dutree.py
+2
-2
eptags.py
Tools/scripts/eptags.py
+2
-1
finddiv.py
Tools/scripts/finddiv.py
+1
-1
fixnotice.py
Tools/scripts/fixnotice.py
+4
-8
fixps.py
Tools/scripts/fixps.py
+2
-4
get-remote-certificate.py
Tools/scripts/get-remote-certificate.py
+3
-6
h2py.py
Tools/scripts/h2py.py
+3
-4
ifdef.py
Tools/scripts/ifdef.py
+1
-2
md5sum.py
Tools/scripts/md5sum.py
+1
-1
mkreal.py
Tools/scripts/mkreal.py
+2
-3
nm2def.py
Tools/scripts/nm2def.py
+3
-2
objgraph.py
Tools/scripts/objgraph.py
+2
-1
parseentities.py
Tools/scripts/parseentities.py
+9
-7
pathfix.py
Tools/scripts/pathfix.py
+2
-4
pdeps.py
Tools/scripts/pdeps.py
+1
-2
ptags.py
Tools/scripts/ptags.py
+2
-1
rgrep.py
Tools/scripts/rgrep.py
+1
-0
gencjkcodecs.py
Tools/unicode/gencjkcodecs.py
+2
-1
gencodec.py
Tools/unicode/gencodec.py
+5
-8
No files found.
Tools/demo/markov.py
Dosyayı görüntüle @
172bb394
...
...
@@ -78,9 +78,9 @@ def test():
continue
else
:
f
=
open
(
filename
,
'r'
)
with
f
:
if
debug
:
print
(
'processing'
,
filename
,
'...'
)
text
=
f
.
read
()
f
.
close
()
paralist
=
text
.
split
(
'
\n\n
'
)
for
para
in
paralist
:
if
debug
>
1
:
print
(
'feeding ...'
)
...
...
Tools/demo/rpython.py
Dosyayı görüntüle @
172bb394
...
...
@@ -22,7 +22,7 @@ def main():
port
=
int
(
port
[
i
+
1
:])
host
=
host
[:
i
]
command
=
' '
.
join
(
sys
.
argv
[
2
:])
s
=
socket
(
AF_INET
,
SOCK_STREAM
)
with
socket
(
AF_INET
,
SOCK_STREAM
)
as
s
:
s
.
connect
((
host
,
port
))
s
.
send
(
command
.
encode
())
s
.
shutdown
(
SHUT_WR
)
...
...
@@ -33,6 +33,5 @@ def main():
break
reply
+=
data
print
(
reply
.
decode
(),
end
=
' '
)
s
.
close
()
main
()
Tools/demo/rpythond.py
Dosyayı görüntüle @
172bb394
...
...
@@ -26,6 +26,7 @@ def main():
s
.
listen
(
1
)
while
True
:
conn
,
(
remotehost
,
remoteport
)
=
s
.
accept
()
with
conn
:
print
(
'connection from'
,
remotehost
,
remoteport
)
request
=
b
''
while
1
:
...
...
@@ -35,7 +36,6 @@ def main():
request
+=
data
reply
=
execute
(
request
.
decode
())
conn
.
send
(
reply
.
encode
())
conn
.
close
()
def
execute
(
request
):
stdout
=
sys
.
stdout
...
...
Tools/freeze/checkextensions_win32.py
Dosyayı görüntüle @
172bb394
...
...
@@ -130,7 +130,8 @@ def parse_dsp(dsp):
ret
=
[]
dsp_path
,
dsp_name
=
os
.
path
.
split
(
dsp
)
try
:
lines
=
open
(
dsp
,
"r"
)
.
readlines
()
with
open
(
dsp
,
"r"
)
as
fp
:
lines
=
fp
.
readlines
()
except
IOError
as
msg
:
sys
.
stderr
.
write
(
"
%
s:
%
s
\n
"
%
(
dsp
,
msg
))
return
None
...
...
Tools/freeze/freeze.py
Dosyayı görüntüle @
172bb394
...
...
@@ -142,7 +142,8 @@ def main():
# last option can not be "-i", so this ensures "pos+1" is in range!
if
sys
.
argv
[
pos
]
==
'-i'
:
try
:
options
=
open
(
sys
.
argv
[
pos
+
1
])
.
read
()
.
split
()
with
open
(
sys
.
argv
[
pos
+
1
])
as
infp
:
options
=
infp
.
read
()
.
split
()
except
IOError
as
why
:
usage
(
"File name '
%
s' specified with the -i option "
"can not be read -
%
s"
%
(
sys
.
argv
[
pos
+
1
],
why
)
)
...
...
Tools/i18n/pygettext.py
Dosyayı görüntüle @
172bb394
...
...
@@ -561,9 +561,8 @@ def main():
# initialize list of strings to exclude
if
options
.
excludefilename
:
try
:
fp
=
open
(
options
.
excludefilename
)
with
open
(
options
.
excludefilename
)
as
fp
:
options
.
toexclude
=
fp
.
readlines
()
fp
.
close
()
except
IOError
:
print
(
_
(
"Can't read --exclude-file:
%
s"
)
%
options
.
excludefilename
,
file
=
sys
.
stderr
)
...
...
Tools/scripts/cleanfuture.py
Dosyayı görüntüle @
172bb394
...
...
@@ -96,11 +96,11 @@ def check(file):
errprint
(
"
%
r: I/O Error:
%
s"
%
(
file
,
str
(
msg
)))
return
with
f
:
ff
=
FutureFinder
(
f
,
file
)
changed
=
ff
.
run
()
if
changed
:
ff
.
gettherest
()
f
.
close
()
if
changed
:
if
verbose
:
print
(
"changed."
)
...
...
@@ -122,9 +122,8 @@ def check(file):
os
.
rename
(
file
,
bak
)
if
verbose
:
print
(
"renamed"
,
file
,
"to"
,
bak
)
g
=
open
(
file
,
"w"
)
with
open
(
file
,
"w"
)
as
g
:
ff
.
write
(
g
)
g
.
close
()
if
verbose
:
print
(
"wrote new"
,
file
)
else
:
...
...
Tools/scripts/combinerefs.py
Dosyayı görüntüle @
172bb394
...
...
@@ -85,9 +85,7 @@ def read(fileiter, pat, whilematch):
else
:
break
def
combine
(
fname
):
f
=
open
(
fname
)
def
combinefile
(
f
):
fi
=
iter
(
f
)
for
line
in
read
(
fi
,
re
.
compile
(
r'^Remaining objects:$'
),
False
):
...
...
@@ -121,8 +119,11 @@ def combine(fname):
print
(
'[
%
s->
%
s]'
%
(
addr2rc
[
addr
],
rc
),
end
=
' '
)
print
(
guts
,
addr2guts
[
addr
])
f
.
close
()
print
(
"
%
d objects before,
%
d after"
%
(
before
,
after
))
def
combine
(
fname
):
with
open
(
fname
)
as
f
:
combinefile
(
f
)
if
__name__
==
'__main__'
:
combine
(
sys
.
argv
[
1
])
Tools/scripts/dutree.py
Dosyayı görüntüle @
172bb394
...
...
@@ -4,9 +4,9 @@
import
os
,
sys
,
errno
def
main
():
p
=
os
.
popen
(
'du '
+
' '
.
join
(
sys
.
argv
[
1
:]),
'r'
)
total
,
d
=
None
,
{}
for
line
in
p
.
readlines
():
with
os
.
popen
(
'du '
+
' '
.
join
(
sys
.
argv
[
1
:]))
as
p
:
for
line
in
p
:
i
=
0
while
line
[
i
]
in
'0123456789'
:
i
=
i
+
1
size
=
eval
(
line
[:
i
])
...
...
Tools/scripts/eptags.py
Dosyayı görüntüle @
172bb394
...
...
@@ -28,6 +28,7 @@ def treat_file(filename, outfp):
except
OSError
:
sys
.
stderr
.
write
(
'Cannot open
%
s
\n
'
%
filename
)
return
with
fp
:
charno
=
0
lineno
=
0
tags
=
[]
...
...
@@ -48,7 +49,7 @@ def treat_file(filename, outfp):
outfp
.
write
(
tag
)
def
main
():
outfp
=
open
(
'TAGS'
,
'w'
)
with
open
(
'TAGS'
,
'w'
)
as
outfp
:
for
filename
in
sys
.
argv
[
1
:]:
treat_file
(
filename
,
outfp
)
...
...
Tools/scripts/finddiv.py
Dosyayı görüntüle @
172bb394
...
...
@@ -55,6 +55,7 @@ def process(filename, listnames):
except
IOError
as
msg
:
sys
.
stderr
.
write
(
"Can't open:
%
s
\n
"
%
msg
)
return
1
with
fp
:
g
=
tokenize
.
generate_tokens
(
fp
.
readline
)
lastrow
=
None
for
type
,
token
,
(
row
,
col
),
end
,
line
in
g
:
...
...
@@ -65,7 +66,6 @@ def process(filename, listnames):
if
row
!=
lastrow
:
lastrow
=
row
print
(
"
%
s:
%
d:
%
s"
%
(
filename
,
row
,
line
),
end
=
' '
)
fp
.
close
()
def
processdir
(
dir
,
listnames
):
try
:
...
...
Tools/scripts/fixnotice.py
Dosyayı görüntüle @
172bb394
...
...
@@ -73,22 +73,19 @@ def main():
elif
opt
==
'--dry-run'
:
DRYRUN
=
1
elif
opt
==
'--oldnotice'
:
fp
=
open
(
arg
)
with
open
(
arg
)
as
fp
:
OLD_NOTICE
=
fp
.
read
()
fp
.
close
()
elif
opt
==
'--newnotice'
:
fp
=
open
(
arg
)
with
open
(
arg
)
as
fp
:
NEW_NOTICE
=
fp
.
read
()
fp
.
close
()
for
arg
in
args
:
process
(
arg
)
def
process
(
file
):
f
=
open
(
file
)
with
open
(
file
)
as
f
:
data
=
f
.
read
()
f
.
close
()
i
=
data
.
find
(
OLD_NOTICE
)
if
i
<
0
:
if
VERBOSE
:
...
...
@@ -102,9 +99,8 @@ def process(file):
data
=
data
[:
i
]
+
NEW_NOTICE
+
data
[
i
+
len
(
OLD_NOTICE
):]
new
=
file
+
".new"
backup
=
file
+
".bak"
f
=
open
(
new
,
"w"
)
with
open
(
new
,
"w"
)
as
f
:
f
.
write
(
data
)
f
.
close
()
os
.
rename
(
file
,
backup
)
os
.
rename
(
new
,
file
)
...
...
Tools/scripts/fixps.py
Dosyayı görüntüle @
172bb394
...
...
@@ -14,20 +14,18 @@ def main():
except
IOError
as
msg
:
print
(
filename
,
': can
\'
t open :'
,
msg
)
continue
with
f
:
line
=
f
.
readline
()
if
not
re
.
match
(
'^#! */usr/local/bin/python'
,
line
):
print
(
filename
,
': not a /usr/local/bin/python script'
)
f
.
close
()
continue
rest
=
f
.
read
()
f
.
close
()
line
=
re
.
sub
(
'/usr/local/bin/python'
,
'/usr/bin/env python'
,
line
)
print
(
filename
,
':'
,
repr
(
line
))
f
=
open
(
filename
,
"w"
)
with
open
(
filename
,
"w"
)
as
f
:
f
.
write
(
line
)
f
.
write
(
rest
)
f
.
close
()
if
__name__
==
'__main__'
:
main
()
Tools/scripts/get-remote-certificate.py
Dosyayı görüntüle @
172bb394
...
...
@@ -29,9 +29,8 @@ def fetch_server_certificate (host, port):
return
None
else
:
tn
=
tempfile
.
mktemp
()
fp
=
open
(
tn
,
"wb"
)
with
open
(
tn
,
"wb"
)
as
fp
:
fp
.
write
(
m
.
group
(
1
)
+
b
"
\n
"
)
fp
.
close
()
try
:
tn2
=
(
outfile
or
tempfile
.
mktemp
())
status
,
output
=
subproc
(
r'openssl x509 -in "
%
s" -out "
%
s"'
%
...
...
@@ -39,9 +38,8 @@ def fetch_server_certificate (host, port):
if
status
!=
0
:
raise
RuntimeError
(
'OpenSSL x509 failed with status
%
s and '
'output:
%
r'
%
(
status
,
output
))
fp
=
open
(
tn2
,
'rb'
)
with
open
(
tn2
,
'rb'
)
as
fp
:
data
=
fp
.
read
()
fp
.
close
()
os
.
unlink
(
tn2
)
return
data
finally
:
...
...
@@ -49,9 +47,8 @@ def fetch_server_certificate (host, port):
if
sys
.
platform
.
startswith
(
"win"
):
tfile
=
tempfile
.
mktemp
()
fp
=
open
(
tfile
,
"w"
)
with
open
(
tfile
,
"w"
)
as
fp
:
fp
.
write
(
"quit
\n
"
)
fp
.
close
()
try
:
status
,
output
=
subproc
(
'openssl s_client -connect "
%
s:
%
s" -showcerts < "
%
s"'
%
...
...
Tools/scripts/h2py.py
Dosyayı görüntüle @
172bb394
...
...
@@ -69,13 +69,13 @@ def main():
sys
.
stdout
.
write
(
'# Generated by h2py from stdin
\n
'
)
process
(
sys
.
stdin
,
sys
.
stdout
)
else
:
fp
=
open
(
filename
,
'r'
)
with
open
(
filename
)
as
fp
:
outfile
=
os
.
path
.
basename
(
filename
)
i
=
outfile
.
rfind
(
'.'
)
if
i
>
0
:
outfile
=
outfile
[:
i
]
modname
=
outfile
.
upper
()
outfile
=
modname
+
'.py'
outfp
=
open
(
outfile
,
'w'
)
with
open
(
outfile
,
'w'
)
as
outfp
:
outfp
.
write
(
'# Generated by h2py from
%
s
\n
'
%
filename
)
filedict
=
{}
for
dir
in
searchdirs
:
...
...
@@ -84,8 +84,6 @@ def main():
importable
[
filename
[
len
(
dir
)
+
1
:]]
=
modname
break
process
(
fp
,
outfp
)
outfp
.
close
()
fp
.
close
()
def
pytify
(
body
):
# replace ignored patterns by spaces
...
...
@@ -161,6 +159,7 @@ def process(fp, outfp, env = {}):
except
IOError
:
pass
if
inclfp
:
with
inclfp
:
outfp
.
write
(
'
\n
# Included from
%
s
\n
'
%
filename
)
process
(
inclfp
,
outfp
,
env
)
...
...
Tools/scripts/ifdef.py
Dosyayı görüntüle @
172bb394
...
...
@@ -45,9 +45,8 @@ def main():
if
filename
==
'-'
:
process
(
sys
.
stdin
,
sys
.
stdout
)
else
:
f
=
open
(
filename
,
'r'
)
with
open
(
filename
)
as
f
:
process
(
f
,
sys
.
stdout
)
f
.
close
()
def
process
(
fpi
,
fpo
):
keywords
=
(
'if'
,
'ifdef'
,
'ifndef'
,
'else'
,
'endif'
)
...
...
Tools/scripts/md5sum.py
Dosyayı görüntüle @
172bb394
...
...
@@ -47,10 +47,10 @@ def printsum(filename, out=sys.stdout):
except
IOError
as
msg
:
sys
.
stderr
.
write
(
'
%
s: Can
\'
t open:
%
s
\n
'
%
(
filename
,
msg
))
return
1
with
fp
:
if
fnfilter
:
filename
=
fnfilter
(
filename
)
sts
=
printsumfp
(
fp
,
filename
,
out
)
fp
.
close
()
return
sts
def
printsumfp
(
fp
,
filename
,
out
=
sys
.
stdout
):
...
...
Tools/scripts/mkreal.py
Dosyayı görüntüle @
172bb394
...
...
@@ -18,14 +18,13 @@ def mkrealfile(name):
st
=
os
.
stat
(
name
)
# Get the mode
mode
=
S_IMODE
(
st
[
ST_MODE
])
linkto
=
os
.
readlink
(
name
)
# Make sure again it's a symlink
f_in
=
open
(
name
,
'r'
)
# This ensures it's a file
with
open
(
name
,
'rb'
)
as
f_in
:
# This ensures it's a file
os
.
unlink
(
name
)
f_out
=
open
(
name
,
'w'
)
with
open
(
name
,
'wb'
)
as
f_out
:
while
1
:
buf
=
f_in
.
read
(
BUFSIZE
)
if
not
buf
:
break
f_out
.
write
(
buf
)
del
f_out
# Flush data to disk before changing mode
os
.
chmod
(
name
,
mode
)
def
mkrealdir
(
name
):
...
...
Tools/scripts/nm2def.py
Dosyayı görüntüle @
172bb394
...
...
@@ -42,7 +42,8 @@ NM = 'nm -p -g %s' # For Linux, use "nm -g %s"
def
symbols
(
lib
=
PYTHONLIB
,
types
=
(
'T'
,
'C'
,
'D'
)):
lines
=
os
.
popen
(
NM
%
lib
)
.
readlines
()
with
os
.
popen
(
NM
%
lib
)
as
pipe
:
lines
=
pipe
.
readlines
()
lines
=
[
s
.
strip
()
for
s
in
lines
]
symbols
=
{}
for
line
in
lines
:
...
...
@@ -97,7 +98,7 @@ def main():
exports
=
export_list
(
s
)
f
=
sys
.
stdout
# open('PC/python_nt.def','w')
f
.
write
(
DEF_TEMPLATE
%
(
exports
))
f
.
close
()
#
f.close()
if
__name__
==
'__main__'
:
main
()
Tools/scripts/objgraph.py
Dosyayı görüntüle @
172bb394
...
...
@@ -180,7 +180,8 @@ def main():
if
filename
==
'-'
:
readinput
(
sys
.
stdin
)
else
:
readinput
(
open
(
filename
,
'r'
))
with
open
(
filename
)
as
f
:
readinput
(
f
)
#
warndups
()
#
...
...
Tools/scripts/parseentities.py
Dosyayı görüntüle @
172bb394
...
...
@@ -50,13 +50,15 @@ def writefile(f,defs):
if
__name__
==
'__main__'
:
if
len
(
sys
.
argv
)
>
1
:
infile
=
open
(
sys
.
argv
[
1
])
with
open
(
sys
.
argv
[
1
])
as
infile
:
text
=
infile
.
read
()
else
:
infile
=
sys
.
stdin
text
=
sys
.
stdin
.
read
()
defs
=
parse
(
text
)
if
len
(
sys
.
argv
)
>
2
:
outfile
=
open
(
sys
.
argv
[
2
],
'w'
)
with
open
(
sys
.
argv
[
2
],
'w'
)
as
outfile
:
writefile
(
outfile
,
defs
)
else
:
outfile
=
sys
.
stdout
text
=
infile
.
read
()
defs
=
parse
(
text
)
writefile
(
outfile
,
defs
)
writefile
(
sys
.
stdout
,
defs
)
Tools/scripts/pathfix.py
Dosyayı görüntüle @
172bb394
...
...
@@ -103,20 +103,20 @@ def fix(filename):
except
IOError
as
msg
:
err
(
'
%
s: cannot open:
%
r
\n
'
%
(
filename
,
msg
))
return
1
with
f
:
line
=
f
.
readline
()
fixed
=
fixline
(
line
)
if
line
==
fixed
:
rep
(
filename
+
': no change
\n
'
)
f
.
close
()
return
head
,
tail
=
os
.
path
.
split
(
filename
)
tempname
=
os
.
path
.
join
(
head
,
'@'
+
tail
)
try
:
g
=
open
(
tempname
,
'wb'
)
except
IOError
as
msg
:
f
.
close
()
err
(
'
%
s: cannot create:
%
r
\n
'
%
(
tempname
,
msg
))
return
1
with
g
:
rep
(
filename
+
': updating
\n
'
)
g
.
write
(
fixed
)
BUFSIZE
=
8
*
1024
...
...
@@ -124,8 +124,6 @@ def fix(filename):
buf
=
f
.
read
(
BUFSIZE
)
if
not
buf
:
break
g
.
write
(
buf
)
g
.
close
()
f
.
close
()
# Finishing touch -- move files
...
...
Tools/scripts/pdeps.py
Dosyayı görüntüle @
172bb394
...
...
@@ -64,7 +64,7 @@ m_from = re.compile('^[ \t]*import[ \t]+([^#]+)')
# Collect data from one file
#
def
process
(
filename
,
table
):
fp
=
open
(
filename
,
'r'
)
with
open
(
filename
)
as
fp
:
mod
=
os
.
path
.
basename
(
filename
)
if
mod
[
-
3
:]
==
'.py'
:
mod
=
mod
[:
-
3
]
...
...
@@ -86,7 +86,6 @@ def process(filename, table):
word
=
word
.
strip
()
if
word
not
in
list
:
list
.
append
(
word
)
fp
.
close
()
# Compute closure (this is in fact totally general)
...
...
Tools/scripts/ptags.py
Dosyayı görüntüle @
172bb394
...
...
@@ -19,7 +19,7 @@ def main():
for
filename
in
args
:
treat_file
(
filename
)
if
tags
:
fp
=
open
(
'tags'
,
'w'
)
with
open
(
'tags'
,
'w'
)
as
fp
:
tags
.
sort
()
for
s
in
tags
:
fp
.
write
(
s
)
...
...
@@ -33,6 +33,7 @@ def treat_file(filename):
except
:
sys
.
stderr
.
write
(
'Cannot open
%
s
\n
'
%
filename
)
return
with
fp
:
base
=
os
.
path
.
basename
(
filename
)
if
base
[
-
3
:]
==
'.py'
:
base
=
base
[:
-
3
]
...
...
Tools/scripts/rgrep.py
Dosyayı görüntüle @
172bb394
...
...
@@ -30,6 +30,7 @@ def main():
f
=
open
(
filename
)
except
IOError
as
msg
:
usage
(
"can't open
%
r:
%
s"
%
(
filename
,
msg
),
1
)
with
f
:
f
.
seek
(
0
,
2
)
pos
=
f
.
tell
()
leftover
=
None
...
...
Tools/unicode/gencjkcodecs.py
Dosyayı görüntüle @
172bb394
...
...
@@ -61,7 +61,8 @@ def gencodecs(prefix):
encoding
=
enc
.
lower
(),
owner
=
loc
)
codecpath
=
os
.
path
.
join
(
prefix
,
enc
+
'.py'
)
open
(
codecpath
,
'w'
)
.
write
(
code
)
with
open
(
codecpath
,
'w'
)
as
f
:
f
.
write
(
code
)
if
__name__
==
'__main__'
:
import
sys
...
...
Tools/unicode/gencodec.py
Dosyayı görüntüle @
172bb394
...
...
@@ -72,9 +72,8 @@ def parsecodes(codes, len=len, range=range):
def
readmap
(
filename
):
f
=
open
(
filename
,
'r'
)
with
open
(
filename
)
as
f
:
lines
=
f
.
readlines
()
f
.
close
()
enc2uni
=
{}
identity
=
[]
unmapped
=
list
(
range
(
256
))
...
...
@@ -359,18 +358,16 @@ encoding_table = codecs.charmap_build(decoding_table)
def
pymap
(
name
,
map
,
pyfile
,
encodingname
,
comments
=
1
):
code
=
codegen
(
name
,
map
,
encodingname
,
comments
)
f
=
open
(
pyfile
,
'w'
)
with
open
(
pyfile
,
'w'
)
as
f
:
f
.
write
(
code
)
f
.
close
()
def
marshalmap
(
name
,
map
,
marshalfile
):
d
=
{}
for
e
,(
u
,
c
)
in
map
.
items
():
d
[
e
]
=
(
u
,
c
)
f
=
open
(
marshalfile
,
'wb'
)
with
open
(
marshalfile
,
'wb'
)
as
f
:
marshal
.
dump
(
d
,
f
)
f
.
close
()
def
convertdir
(
dir
,
dirprefix
=
''
,
nameprefix
=
''
,
comments
=
1
):
...
...
@@ -411,8 +408,8 @@ def rewritepythondir(dir, dirprefix='', comments=1):
print
(
'converting
%
s to
%
s'
%
(
mapname
,
dirprefix
+
codefile
))
try
:
map
=
marshal
.
load
(
open
(
os
.
path
.
join
(
dir
,
mapname
),
'rb'
)
)
with
open
(
os
.
path
.
join
(
dir
,
mapname
),
'rb'
)
as
f
:
map
=
marshal
.
load
(
f
)
if
not
map
:
print
(
'* map is empty; skipping'
)
else
:
...
...
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