mirror of
https://github.com/python/cpython.git
synced 2025-08-24 10:45:53 +00:00
bpo-22831: Use "with" to avoid possible fd leaks in tools (part 2). (GH-10927)
This commit is contained in:
parent
afbb7a371f
commit
172bb39452
27 changed files with 249 additions and 259 deletions
|
@ -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
|
||||
if len(sys.argv) > 2:
|
||||
outfile = open(sys.argv[2],'w')
|
||||
else:
|
||||
outfile = sys.stdout
|
||||
text = infile.read()
|
||||
text = sys.stdin.read()
|
||||
|
||||
defs = parse(text)
|
||||
writefile(outfile,defs)
|
||||
|
||||
if len(sys.argv) > 2:
|
||||
with open(sys.argv[2],'w') as outfile:
|
||||
writefile(outfile, defs)
|
||||
else:
|
||||
writefile(sys.stdout, defs)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue