mirror of
https://github.com/python/cpython.git
synced 2025-07-07 19:35:27 +00:00
Issue #22831: Use "with" to avoid possible fd leaks.
This commit is contained in:
parent
ae2d667ae8
commit
46ba6c8563
10 changed files with 107 additions and 120 deletions
12
Lib/token.py
12
Lib/token.py
|
@ -97,8 +97,8 @@ def _main():
|
|||
except OSError as err:
|
||||
sys.stdout.write("I/O error: %s\n" % str(err))
|
||||
sys.exit(1)
|
||||
lines = fp.read().split("\n")
|
||||
fp.close()
|
||||
with fp:
|
||||
lines = fp.read().split("\n")
|
||||
prog = re.compile(
|
||||
"#define[ \t][ \t]*([A-Z0-9][A-Z0-9_]*)[ \t][ \t]*([0-9][0-9]*)",
|
||||
re.IGNORECASE)
|
||||
|
@ -116,8 +116,8 @@ def _main():
|
|||
except OSError as err:
|
||||
sys.stderr.write("I/O error: %s\n" % str(err))
|
||||
sys.exit(2)
|
||||
format = fp.read().split("\n")
|
||||
fp.close()
|
||||
with fp:
|
||||
format = fp.read().split("\n")
|
||||
try:
|
||||
start = format.index("#--start constants--") + 1
|
||||
end = format.index("#--end constants--")
|
||||
|
@ -133,8 +133,8 @@ def _main():
|
|||
except OSError as err:
|
||||
sys.stderr.write("I/O error: %s\n" % str(err))
|
||||
sys.exit(4)
|
||||
fp.write("\n".join(format))
|
||||
fp.close()
|
||||
with fp:
|
||||
fp.write("\n".join(format))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue