summaryrefslogtreecommitdiff
path: root/Tools/scripts/parseentities.py
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2019-03-30 08:33:02 +0200
committerGitHub <noreply@github.com>2019-03-30 08:33:02 +0200
commit172bb39452ae8b3ccdf5d1f23ead46f44200cd49 (patch)
tree5e1effbca3664b839a81eb7a7d62fa4974cfbfb1 /Tools/scripts/parseentities.py
parentafbb7a371fb44edc731344eab5b474ad8f7b57d7 (diff)
downloadcpython-git-172bb39452ae8b3ccdf5d1f23ead46f44200cd49.tar.gz
bpo-22831: Use "with" to avoid possible fd leaks in tools (part 2). (GH-10927)
Diffstat (limited to 'Tools/scripts/parseentities.py')
-rwxr-xr-xTools/scripts/parseentities.py16
1 files changed, 9 insertions, 7 deletions
diff --git a/Tools/scripts/parseentities.py b/Tools/scripts/parseentities.py
index c686b0241a..0229d3af86 100755
--- a/Tools/scripts/parseentities.py
+++ b/Tools/scripts/parseentities.py
@@ -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)