diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2015-04-04 08:01:02 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2015-04-04 08:01:02 (GMT) |
commit | 46ba6c8563922f043cad6423202ee0119614c807 (patch) | |
tree | 4523d1a3665af25ef77898f7d2da186fbdca8ce7 /Lib/binhex.py | |
parent | ae2d667ae83548029fed7244619fadd7f625cb24 (diff) | |
download | cpython-46ba6c8563922f043cad6423202ee0119614c807.zip cpython-46ba6c8563922f043cad6423202ee0119614c807.tar.gz cpython-46ba6c8563922f043cad6423202ee0119614c807.tar.bz2 |
Issue #22831: Use "with" to avoid possible fd leaks.
Diffstat (limited to 'Lib/binhex.py')
-rw-r--r-- | Lib/binhex.py | 28 |
1 files changed, 13 insertions, 15 deletions
diff --git a/Lib/binhex.py b/Lib/binhex.py index 7bf9278..14badb7 100644 --- a/Lib/binhex.py +++ b/Lib/binhex.py @@ -229,14 +229,13 @@ def binhex(inp, out): finfo = getfileinfo(inp) ofp = BinHex(finfo, out) - ifp = io.open(inp, 'rb') - # XXXX Do textfile translation on non-mac systems - while True: - d = ifp.read(128000) - if not d: break - ofp.write(d) - ofp.close_data() - ifp.close() + with io.open(inp, 'rb') as ifp: + # XXXX Do textfile translation on non-mac systems + while True: + d = ifp.read(128000) + if not d: break + ofp.write(d) + ofp.close_data() ifp = openrsrc(inp, 'rb') while True: @@ -449,13 +448,12 @@ def hexbin(inp, out): if not out: out = ifp.FName - ofp = io.open(out, 'wb') - # XXXX Do translation on non-mac systems - while True: - d = ifp.read(128000) - if not d: break - ofp.write(d) - ofp.close() + with io.open(out, 'wb') as ofp: + # XXXX Do translation on non-mac systems + while True: + d = ifp.read(128000) + if not d: break + ofp.write(d) ifp.close_data() d = ifp.read_rsrc(128000) |