[Python-checkins] r86027 - in python/branches/release27-maint: Lib/uu.py Misc/NEWS

antoine.pitrou python-checkins at python.org
Sun Oct 31 14:12:48 CET 2010


Author: antoine.pitrou
Date: Sun Oct 31 14:12:48 2010
New Revision: 86027

Log:
Merged revisions 85975 via svnmerge from 
svn+ssh://pythondev@svn.python.org/python/branches/py3k

........
  r85975 | antoine.pitrou | 2010-10-30 15:03:56 +0200 (sam., 30 oct. 2010) | 4 lines
  
  Issue #10246: uu.encode didn't close file objects explicitly when filenames
  were given to it.  Patch by Brian Brazil.
........


Modified:
   python/branches/release27-maint/   (props changed)
   python/branches/release27-maint/Lib/uu.py
   python/branches/release27-maint/Misc/NEWS

Modified: python/branches/release27-maint/Lib/uu.py
==============================================================================
--- python/branches/release27-maint/Lib/uu.py	(original)
+++ python/branches/release27-maint/Lib/uu.py	Sun Oct 31 14:12:48 2010
@@ -44,40 +44,47 @@
     #
     # If in_file is a pathname open it and change defaults
     #
-    if in_file == '-':
-        in_file = sys.stdin
-    elif isinstance(in_file, basestring):
+    opened_files = []
+    try:
+        if in_file == '-':
+            in_file = sys.stdin
+        elif isinstance(in_file, basestring):
+            if name is None:
+                name = os.path.basename(in_file)
+            if mode is None:
+                try:
+                    mode = os.stat(in_file).st_mode
+                except AttributeError:
+                    pass
+            in_file = open(in_file, 'rb')
+            opened_files.append(in_file)
+        #
+        # Open out_file if it is a pathname
+        #
+        if out_file == '-':
+            out_file = sys.stdout
+        elif isinstance(out_file, basestring):
+            out_file = open(out_file, 'wb')
+            opened_files.append(out_file)
+        #
+        # Set defaults for name and mode
+        #
         if name is None:
-            name = os.path.basename(in_file)
+            name = '-'
         if mode is None:
-            try:
-                mode = os.stat(in_file).st_mode
-            except AttributeError:
-                pass
-        in_file = open(in_file, 'rb')
-    #
-    # Open out_file if it is a pathname
-    #
-    if out_file == '-':
-        out_file = sys.stdout
-    elif isinstance(out_file, basestring):
-        out_file = open(out_file, 'w')
-    #
-    # Set defaults for name and mode
-    #
-    if name is None:
-        name = '-'
-    if mode is None:
-        mode = 0666
-    #
-    # Write the data
-    #
-    out_file.write('begin %o %s\n' % ((mode&0777),name))
-    data = in_file.read(45)
-    while len(data) > 0:
-        out_file.write(binascii.b2a_uu(data))
+            mode = 0666
+        #
+        # Write the data
+        #
+        out_file.write('begin %o %s\n' % ((mode&0777),name))
         data = in_file.read(45)
-    out_file.write(' \nend\n')
+        while len(data) > 0:
+            out_file.write(binascii.b2a_uu(data))
+            data = in_file.read(45)
+        out_file.write(' \nend\n')
+    finally:
+        for f in opened_files:
+            f.close()
 
 
 def decode(in_file, out_file=None, mode=None, quiet=0):

Modified: python/branches/release27-maint/Misc/NEWS
==============================================================================
--- python/branches/release27-maint/Misc/NEWS	(original)
+++ python/branches/release27-maint/Misc/NEWS	Sun Oct 31 14:12:48 2010
@@ -66,6 +66,9 @@
 Library
 -------
 
+- Issue #10246: uu.encode didn't close file objects explicitly when filenames
+  were given to it.  Patch by Brian Brazil.
+
 - Issue #10253: FileIO leaks a file descriptor when trying to open a file
   for append that isn't seekable.  Patch by Brian Brazil.
 


More information about the Python-checkins mailing list