]> git.phdru.name Git - mimedecode.git/blobdiff - mimedecode.py
Close infile and outfile even after an exception
[mimedecode.git] / mimedecode.py
index b6f139b6974ba2cb141d9c6999085cfdce22a02a..692a0f0d700706799203af81c59a00b9e8df5ef6 100755 (executable)
@@ -30,9 +30,6 @@ Usage: %s [-h|--help] [-V|--version] [-cCDP] [-H|--host=hostname] [-f charset] [
     sys.exit(code)
 
 
-def output(s):
-    gopts.outfile.write(s)
-
 def output_headers(msg):
     unix_from = msg.get_unixfrom()
     if unix_from:
@@ -391,7 +388,10 @@ if __name__ == "__main__":
         gopts.host_name = socket.gethostname()
 
     gopts.outfile = outfile
-    decode_file(infile)
+    output = outfile.write
 
-    infile.close()
-    outfile.close()
+    try:
+        decode_file(infile)
+    finally:
+        infile.close()
+        outfile.close()