mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
bpo-22831: Use "with" to avoid possible fd leaks in tools (part 1). (GH-10926)
This commit is contained in:
parent
2524fdefc9
commit
afbb7a371f
5 changed files with 226 additions and 228 deletions
|
@ -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__':
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue