Jython compatibility fix: if uu.decode() opened its output file, be sure to

close it.
This commit is contained in:
Andrew M. Kuchling 2006-11-20 13:39:37 +00:00
parent 1e753863b3
commit 5dba6f74c6
1 changed files with 4 additions and 0 deletions

View File

@ -114,6 +114,7 @@ def decode(in_file, out_file=None, mode=None, quiet=0):
# #
# Open the output file # Open the output file
# #
opened = False
if out_file == '-': if out_file == '-':
out_file = sys.stdout out_file = sys.stdout
elif isinstance(out_file, basestring): elif isinstance(out_file, basestring):
@ -123,6 +124,7 @@ def decode(in_file, out_file=None, mode=None, quiet=0):
except AttributeError: except AttributeError:
pass pass
out_file = fp out_file = fp
opened = True
# #
# Main decoding loop # Main decoding loop
# #
@ -140,6 +142,8 @@ def decode(in_file, out_file=None, mode=None, quiet=0):
s = in_file.readline() s = in_file.readline()
if not s: if not s:
raise Error('Truncated input file') raise Error('Truncated input file')
if opened:
out_file.close()
def test(): def test():
"""uuencode/uudecode main program""" """uuencode/uudecode main program"""