Commit e305425b authored by Antoine Pitrou's avatar Antoine Pitrou

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.
........
parent 735e3b19
...@@ -44,6 +44,8 @@ def encode(in_file, out_file, name=None, mode=None): ...@@ -44,6 +44,8 @@ def encode(in_file, out_file, name=None, mode=None):
# #
# If in_file is a pathname open it and change defaults # If in_file is a pathname open it and change defaults
# #
opened_files = []
try:
if in_file == '-': if in_file == '-':
in_file = sys.stdin.buffer in_file = sys.stdin.buffer
elif isinstance(in_file, str): elif isinstance(in_file, str):
...@@ -55,6 +57,7 @@ def encode(in_file, out_file, name=None, mode=None): ...@@ -55,6 +57,7 @@ def encode(in_file, out_file, name=None, mode=None):
except AttributeError: except AttributeError:
pass pass
in_file = open(in_file, 'rb') in_file = open(in_file, 'rb')
opened_files.append(in_file)
# #
# Open out_file if it is a pathname # Open out_file if it is a pathname
# #
...@@ -62,6 +65,7 @@ def encode(in_file, out_file, name=None, mode=None): ...@@ -62,6 +65,7 @@ def encode(in_file, out_file, name=None, mode=None):
out_file = sys.stdout.buffer out_file = sys.stdout.buffer
elif isinstance(out_file, str): elif isinstance(out_file, str):
out_file = open(out_file, 'wb') out_file = open(out_file, 'wb')
opened_files.append(out_file)
# #
# Set defaults for name and mode # Set defaults for name and mode
# #
...@@ -78,6 +82,9 @@ def encode(in_file, out_file, name=None, mode=None): ...@@ -78,6 +82,9 @@ def encode(in_file, out_file, name=None, mode=None):
out_file.write(binascii.b2a_uu(data)) out_file.write(binascii.b2a_uu(data))
data = in_file.read(45) data = in_file.read(45)
out_file.write(b' \nend\n') out_file.write(b' \nend\n')
finally:
for f in opened_files:
f.close()
def decode(in_file, out_file=None, mode=None, quiet=False): def decode(in_file, out_file=None, mode=None, quiet=False):
......
...@@ -143,6 +143,9 @@ C-API ...@@ -143,6 +143,9 @@ C-API
Library 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 - Issue #10253: FileIO leaks a file descriptor when trying to open a file
for append that isn't seekable. Patch by Brian Brazil. for append that isn't seekable. Patch by Brian Brazil.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment