From: Oleg Broytman Date: Thu, 13 Mar 2014 21:17:02 +0000 (+0400) Subject: open_output_file X-Git-Tag: v2.5.0~13 X-Git-Url: https://git.phdru.name/?a=commitdiff_plain;h=b92e86cc18ad38cd2c8db1a3217ca2fed1c50c2f;p=mimedecode.git open_output_file --- diff --git a/mimedecode.py b/mimedecode.py index 01f6505..392e707 100755 --- a/mimedecode.py +++ b/mimedecode.py @@ -279,7 +279,7 @@ def _save_message(msg, outstring, save_headers=False, save_body=False): global output save_output = output - outfile = open(os.path.join(g.destination_dir, fname), 'w') + outfile = open_output_file(fname) output = outfile.write if save_headers: output_headers(msg) @@ -395,6 +395,10 @@ def decode_message(msg): output(msg.as_string()) +def open_output_file(filename): + return open(os.path.join(g.destination_dir, filename), 'w') + + class GlobalOptions: from m_lib.defenc import default_encoding recode_charset = 1 # recode charset of message body @@ -521,7 +525,7 @@ if __name__ == "__main__": g.input_filename = '-' infile = sys.stdin if g.output_filename: - outfile = open(os.path.join(g.destination_dir, g.output_filename), 'w') + outfile = open_output_file(g.output_filename) else: g.output_filename = '-' outfile = sys.stdout @@ -534,7 +538,7 @@ if __name__ == "__main__": infile = open(arguments[0], 'r') if la == 1: if g.output_filename: - outfile = open(os.path.join(g.destination_dir, g.output_filename), 'w') + outfile = open_output_file(g.output_filename) else: g.output_filename = '-' outfile = sys.stdout @@ -546,7 +550,7 @@ if __name__ == "__main__": outfile = sys.stdout else: g.output_filename = arguments[1] - outfile = open(os.path.join(g.destination_dir, g.output_filename), 'w') + outfile = open_output_file(g.output_filename) else: usage(1, 'Too many arguments')