Issue #22831: Use "with" to avoid possible fd leaks.
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 @@
     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 @@
     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)