mirror of
https://github.com/python/cpython.git
synced 2025-09-26 10:19: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
|
@ -130,7 +130,8 @@ def parse_dsp(dsp):
|
|||
ret = []
|
||||
dsp_path, dsp_name = os.path.split(dsp)
|
||||
try:
|
||||
lines = open(dsp, "r").readlines()
|
||||
with open(dsp, "r") as fp:
|
||||
lines = fp.readlines()
|
||||
except IOError as msg:
|
||||
sys.stderr.write("%s: %s\n" % (dsp, msg))
|
||||
return None
|
||||
|
|
|
@ -142,7 +142,8 @@ def main():
|
|||
# last option can not be "-i", so this ensures "pos+1" is in range!
|
||||
if sys.argv[pos] == '-i':
|
||||
try:
|
||||
options = open(sys.argv[pos+1]).read().split()
|
||||
with open(sys.argv[pos+1]) as infp:
|
||||
options = infp.read().split()
|
||||
except IOError as why:
|
||||
usage("File name '%s' specified with the -i option "
|
||||
"can not be read - %s" % (sys.argv[pos+1], why) )
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue