bpo-22831: Use "with" to avoid possible fd leaks in tools (part 1). (GH-10926)

This commit is contained in:
Serhiy Storchaka 2019-03-30 08:32:18 +02:00 committed by GitHub
parent 2524fdefc9
commit afbb7a371f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 226 additions and 228 deletions

View file

@ -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__':