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
afbb7a37
Commit
afbb7a37
authored
Mar 30, 2019
by
Serhiy Storchaka
Committed by
GitHub
Mar 30, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bpo-22831: Use "with" to avoid possible fd leaks in tools (part 1). (GH-10926)
parent
2524fdef
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
226 additions
and
228 deletions
+226
-228
Tools/scripts/fixcid.py
Tools/scripts/fixcid.py
+30
-30
Tools/scripts/fixdiv.py
Tools/scripts/fixdiv.py
+93
-93
Tools/scripts/fixheader.py
Tools/scripts/fixheader.py
+21
-21
Tools/scripts/gprof2html.py
Tools/scripts/gprof2html.py
+11
-9
Tools/scripts/texi2html.py
Tools/scripts/texi2html.py
+71
-75
No files found.
Tools/scripts/fixcid.py
View file @
afbb7a37
...
...
@@ -281,6 +281,7 @@ def addsubst(substfile):
except
IOError
as
msg
:
err
(
substfile
+
': cannot read substfile: '
+
str
(
msg
)
+
'
\
n
'
)
sys
.
exit
(
1
)
with
fp
:
lineno
=
0
while
1
:
line
=
fp
.
readline
()
...
...
@@ -310,7 +311,6 @@ def addsubst(substfile):
err
(
'%s:%r: warning: overriding: %r %r
\
n
'
%
(
substfile
,
lineno
,
key
,
value
))
err
(
'%s:%r: warning: previous: %r
\
n
'
%
(
substfile
,
lineno
,
Dict
[
key
]))
Dict
[
key
]
=
value
fp
.
close
()
if
__name__
==
'__main__'
:
main
()
Tools/scripts/fixdiv.py
View file @
afbb7a37
...
...
@@ -179,12 +179,13 @@ PATTERN = (r"^(.+?):(\d+): DeprecationWarning: "
def
readwarnings
(
warningsfile
):
prog
=
re
.
compile
(
PATTERN
)
warnings
=
{}
try
:
f
=
open
(
warningsfile
)
except
IOError
as
msg
:
sys
.
stderr
.
write
(
"can't open: %s
\
n
"
%
msg
)
return
w
arnings
=
{}
w
ith
f
:
while
1
:
line
=
f
.
readline
()
if
not
line
:
...
...
@@ -199,7 +200,6 @@ def readwarnings(warningsfile):
if
list
is
None
:
warnings
[
filename
]
=
list
=
[]
list
.
append
((
int
(
lineno
),
sys
.
intern
(
what
)))
f
.
close
()
return
warnings
def
process
(
filename
,
list
):
...
...
@@ -210,6 +210,7 @@ def process(filename, list):
except
IOError
as
msg
:
sys
.
stderr
.
write
(
"can't open: %s
\
n
"
%
msg
)
return
1
with
fp
:
print
(
"Index:"
,
filename
)
f
=
FileContext
(
fp
)
list
.
sort
()
...
...
@@ -284,10 +285,9 @@ def process(filename, list):
print
(
"True division / operator at line %d:"
%
row
)
print
(
"="
,
line
)
elif
intlong
and
floatcomplex
:
print
(
"*** Ambiguous / operator (%s, %s) at line %d:"
%
(
"|"
.
join
(
intlong
),
"|"
.
join
(
floatcomplex
),
row
))
print
(
"*** Ambiguous / operator (%s, %s) at line %d:"
%
(
"|"
.
join
(
intlong
),
"|"
.
join
(
floatcomplex
),
row
))
print
(
"?"
,
line
)
fp
.
close
()
def
reportphantomwarnings
(
warnings
,
f
):
blocks
=
[]
...
...
Tools/scripts/fixheader.py
View file @
afbb7a37
...
...
@@ -15,8 +15,8 @@ def process(filename):
except
IOError
as
msg
:
sys
.
stderr
.
write
(
'%s: can
\
'
t open: %s
\
n
'
%
(
filename
,
str
(
msg
)))
return
with
f
:
data
=
f
.
read
()
f
.
close
()
if
data
[:
2
]
!=
'/*'
:
sys
.
stderr
.
write
(
'%s does not begin with C comment
\
n
'
%
filename
)
return
...
...
@@ -25,25 +25,25 @@ def process(filename):
except
IOError
as
msg
:
sys
.
stderr
.
write
(
'%s: can
\
'
t write: %s
\
n
'
%
(
filename
,
str
(
msg
)))
return
with
f
:
sys
.
stderr
.
write
(
'Processing %s ...
\
n
'
%
filename
)
magic
=
'Py_'
for
c
in
filename
:
if
ord
(
c
)
<=
0x80
and
c
.
isalnum
():
magic
=
magic
+
c
.
upper
()
else
:
magic
=
magic
+
'_'
sys
.
stdout
=
f
print
(
'#ifndef'
,
magic
)
print
(
'#define'
,
magic
)
print
(
'#ifdef __cplusplus'
)
print
(
'extern "C" {'
)
print
(
'#endif'
)
print
()
print
(
'#ifndef'
,
magic
,
file
=
f
)
print
(
'#define'
,
magic
,
file
=
f
)
print
(
'#ifdef __cplusplus'
,
file
=
f
)
print
(
'extern "C" {'
,
file
=
f
)
print
(
'#endif'
,
file
=
f
)
print
(
file
=
f
)
f
.
write
(
data
)
print
(
)
print
(
'#ifdef __cplusplus'
)
print
(
'}'
)
print
(
'#endif'
)
print
(
'#endif /*'
,
'!'
+
magic
,
'*/'
)
print
(
file
=
f
)
print
(
'#ifdef __cplusplus'
,
file
=
f
)
print
(
'}'
,
file
=
f
)
print
(
'#endif'
,
file
=
f
)
print
(
'#endif /*'
,
'!'
+
magic
,
'*/'
,
file
=
f
)
if
__name__
==
'__main__'
:
main
()
Tools/scripts/gprof2html.py
View file @
afbb7a37
...
...
@@ -28,14 +28,7 @@ def add_escapes(filename):
for
line
in
fp
:
yield
html
.
escape
(
line
)
def
main
():
filename
=
"gprof.out"
if
sys
.
argv
[
1
:]:
filename
=
sys
.
argv
[
1
]
outputfilename
=
filename
+
".html"
input
=
add_escapes
(
filename
)
output
=
open
(
outputfilename
,
"w"
)
def
gprof2html
(
input
,
output
,
filename
):
output
.
write
(
header
%
filename
)
for
line
in
input
:
output
.
write
(
line
)
...
...
@@ -78,7 +71,16 @@ def main():
part = '<a href="
#call:%s">%s</a>' % (part, part)
output
.
write
(
part
)
output
.
write
(
trailer
)
output
.
close
()
def
main
():
filename
=
"gprof.out"
if
sys
.
argv
[
1
:]:
filename
=
sys
.
argv
[
1
]
outputfilename
=
filename
+
".html"
input
=
add_escapes
(
filename
)
with
open
(
outputfilename
,
"w"
)
as
output
:
gprof2html
(
input
,
output
,
filename
)
webbrowser
.
open
(
"file:"
+
os
.
path
.
abspath
(
outputfilename
))
if
__name__
==
'__main__'
:
...
...
Tools/scripts/texi2html.py
View file @
afbb7a37
...
...
@@ -118,11 +118,10 @@ class HTMLNode:
self
.
lines
.
append
(
line
)
def
flush
(
self
):
fp
=
open
(
self
.
dirname
+
'/'
+
makefile
(
self
.
name
),
'w'
)
with
open
(
self
.
dirname
+
'/'
+
makefile
(
self
.
name
),
'w'
)
as
fp
:
fp
.
write
(
self
.
prologue
)
fp
.
write
(
self
.
text
)
fp
.
write
(
self
.
epilogue
)
fp
.
close
()
def
link
(
self
,
label
,
nodename
,
rel
=
None
,
rev
=
None
):
if
nodename
:
...
...
@@ -558,6 +557,7 @@ class TexinfoParser:
except
IOError
as
msg
:
print
(
'*** Can
\
'
t open include file'
,
repr
(
file
))
return
with
fp
:
print
(
'!'
*
self
.
debugging
,
'--> file'
,
repr
(
file
))
save_done
=
self
.
done
save_skip
=
self
.
skip
...
...
@@ -565,7 +565,6 @@ class TexinfoParser:
self
.
includedepth
=
self
.
includedepth
+
1
self
.
parserest
(
fp
,
0
)
self
.
includedepth
=
self
.
includedepth
-
1
fp
.
close
()
self
.
done
=
save_done
self
.
skip
=
save_skip
self
.
stack
=
save_stack
...
...
@@ -1770,7 +1769,7 @@ class HTMLHelp:
# PROJECT FILE
try
:
fp
=
open
(
projectfile
,
'w'
)
with
open
(
projectfile
,
'w'
)
as
fp
:
print
(
'[OPTIONS]'
,
file
=
fp
)
print
(
'Auto Index=Yes'
,
file
=
fp
)
print
(
'Binary TOC=No'
,
file
=
fp
)
...
...
@@ -1794,14 +1793,13 @@ class HTMLHelp:
print
(
'[FILES]'
,
file
=
fp
)
print
(
''
,
file
=
fp
)
self
.
dumpfiles
(
fp
)
fp
.
close
()
except
IOError
as
msg
:
print
(
projectfile
,
':'
,
msg
)
sys
.
exit
(
1
)
# CONTENT FILE
try
:
fp
=
open
(
contentfile
,
'w'
)
with
open
(
contentfile
,
'w'
)
as
fp
:
print
(
'<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">'
,
file
=
fp
)
print
(
'<!-- This file defines the table of contents -->'
,
file
=
fp
)
print
(
'<HTML>'
,
file
=
fp
)
...
...
@@ -1819,14 +1817,13 @@ class HTMLHelp:
self
.
dumpnodes
(
fp
)
print
(
'</BODY>'
,
file
=
fp
)
print
(
'</HTML>'
,
file
=
fp
)
fp
.
close
()
except
IOError
as
msg
:
print
(
contentfile
,
':'
,
msg
)
sys
.
exit
(
1
)
# INDEX FILE
try
:
fp
=
open
(
indexfile
,
'w'
)
with
open
(
indexfile
,
'w'
)
as
fp
:
print
(
'<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">'
,
file
=
fp
)
print
(
'<!-- This file defines the index -->'
,
file
=
fp
)
print
(
'<HTML>'
,
file
=
fp
)
...
...
@@ -1841,7 +1838,6 @@ class HTMLHelp:
self
.
dumpindex
(
fp
)
print
(
'</BODY>'
,
file
=
fp
)
print
(
'</HTML>'
,
file
=
fp
)
fp
.
close
()
except
IOError
as
msg
:
print
(
indexfile
,
':'
,
msg
)
sys
.
exit
(
1
)
...
...
@@ -2064,8 +2060,8 @@ def test():
print
(
file
,
':'
,
msg
)
sys
.
exit
(
1
)
with
fp
:
parser
.
parse
(
fp
)
fp
.
close
()
parser
.
report
()
htmlhelp
.
finalize
()
...
...
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