From: <zy...@us...> - 2008-07-14 12:19:15
|
Revision: 4925 http://jython.svn.sourceforge.net/jython/?rev=4925&view=rev Author: zyasoft Date: 2008-07-14 05:19:10 -0700 (Mon, 14 Jul 2008) Log Message: ----------- Fixed uu.encode, decode so that it does not rely on refcounting to close files Modified Paths: -------------- branches/asm/Lib/uu.py Modified: branches/asm/Lib/uu.py =================================================================== --- branches/asm/Lib/uu.py 2008-07-14 12:11:26 UTC (rev 4924) +++ branches/asm/Lib/uu.py 2008-07-14 12:19:10 UTC (rev 4925) @@ -44,6 +44,10 @@ # # If in_file is a pathname open it and change defaults # + + close_in_file = False + close_out_file = False + if in_file == '-': in_file = sys.stdin elif isinstance(in_file, basestring): @@ -55,6 +59,7 @@ except AttributeError: pass in_file = open(in_file, 'rb') + close_in_file = True # # Open out_file if it is a pathname # @@ -62,6 +67,7 @@ out_file = sys.stdout elif isinstance(out_file, basestring): out_file = open(out_file, 'w') + close_out_file = True # # Set defaults for name and mode # @@ -79,15 +85,26 @@ data = in_file.read(45) out_file.write(' \nend\n') + # Jython and other implementations requires files to be explicitly + # closed if we don't want to wait for GC + if close_in_file: + in_file.close() + if close_out_file: + out_file.close() def decode(in_file, out_file=None, mode=None, quiet=0): """Decode uuencoded file""" + + close_in_file = False + close_out_file = False + # # Open the input file, if needed. # if in_file == '-': in_file = sys.stdin elif isinstance(in_file, basestring): + close_in_file = True in_file = open(in_file) # # Read until a begin is encountered or we've exhausted the file @@ -118,6 +135,7 @@ if out_file == '-': out_file = sys.stdout elif isinstance(out_file, basestring): + close_out_file = True fp = open(out_file, 'wb') try: os.path.chmod(out_file, mode) @@ -145,6 +163,13 @@ if opened: out_file.close() + # Jython and other implementations requires files to be explicitly + # closed if we don't want to wait for GC + if close_in_file: + in_file.close() + if close_out_file: + out_file.close() + def test(): """uuencode/uudecode main program""" This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |