mirror of
https://github.com/python/cpython.git
synced 2025-08-03 16:39:00 +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
|
@ -14,20 +14,18 @@ def main():
|
|||
except IOError as msg:
|
||||
print(filename, ': can\'t open :', msg)
|
||||
continue
|
||||
line = f.readline()
|
||||
if not re.match('^#! */usr/local/bin/python', line):
|
||||
print(filename, ': not a /usr/local/bin/python script')
|
||||
f.close()
|
||||
continue
|
||||
rest = f.read()
|
||||
f.close()
|
||||
with f:
|
||||
line = f.readline()
|
||||
if not re.match('^#! */usr/local/bin/python', line):
|
||||
print(filename, ': not a /usr/local/bin/python script')
|
||||
continue
|
||||
rest = f.read()
|
||||
line = re.sub('/usr/local/bin/python',
|
||||
'/usr/bin/env python', line)
|
||||
print(filename, ':', repr(line))
|
||||
f = open(filename, "w")
|
||||
f.write(line)
|
||||
f.write(rest)
|
||||
f.close()
|
||||
with open(filename, "w") as f:
|
||||
f.write(line)
|
||||
f.write(rest)
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue