[Python-checkins] r63744 - in python/trunk: Lib/tarfile.py Lib/test/test_tarfile.py Misc/NEWS

lars.gustaebel python-checkins at python.org
Tue May 27 14:39:23 CEST 2008


Author: lars.gustaebel
Date: Tue May 27 14:39:23 2008
New Revision: 63744

Log:
Do not close external file objects passed to tarfile.open(mode='w:bz2')
when the TarFile is closed.


Modified:
   python/trunk/Lib/tarfile.py
   python/trunk/Lib/test/test_tarfile.py
   python/trunk/Misc/NEWS

Modified: python/trunk/Lib/tarfile.py
==============================================================================
--- python/trunk/Lib/tarfile.py	(original)
+++ python/trunk/Lib/tarfile.py	Tue May 27 14:39:23 2008
@@ -692,7 +692,6 @@
         if self.mode == "w":
             raw = self.bz2obj.flush()
             self.fileobj.write(raw)
-        self.fileobj.close()
 # class _BZ2Proxy
 
 #------------------------

Modified: python/trunk/Lib/test/test_tarfile.py
==============================================================================
--- python/trunk/Lib/test/test_tarfile.py	(original)
+++ python/trunk/Lib/test/test_tarfile.py	Tue May 27 14:39:23 2008
@@ -529,7 +529,19 @@
         self.assertEqual(float(tarinfo.pax_headers["ctime"]), 1041808783.0)
 
 
-class WriteTest(unittest.TestCase):
+class WriteTestBase(unittest.TestCase):
+    # Put all write tests in here that are supposed to be tested
+    # in all possible mode combinations.
+
+    def test_fileobj_no_close(self):
+        fobj = StringIO.StringIO()
+        tar = tarfile.open(fileobj=fobj, mode=self.mode)
+        tar.addfile(tarfile.TarInfo("foo"))
+        tar.close()
+        self.assert_(fobj.closed is False, "external fileobjs must never closed")
+
+
+class WriteTest(WriteTestBase):
 
     mode = "w:"
 
@@ -652,7 +664,7 @@
             shutil.rmtree(tempdir)
 
 
-class StreamWriteTest(unittest.TestCase):
+class StreamWriteTest(WriteTestBase):
 
     mode = "w|"
 

Modified: python/trunk/Misc/NEWS
==============================================================================
--- python/trunk/Misc/NEWS	(original)
+++ python/trunk/Misc/NEWS	Tue May 27 14:39:23 2008
@@ -63,6 +63,9 @@
 Library
 -------
 
+- Do not close external file objects passed to tarfile.open(mode='w:bz2')
+  when the TarFile is closed.
+
 - Issue #2959: For consistency with other file-like objects, gzip's
   GzipFile.close() can now be called multiple times without raising
   an exception.


More information about the Python-checkins mailing list