]> granicus.if.org Git - python/commitdiff
Patch #1695229: Fix a regression with tarfile.open() and a missing name
authorLars Gustäbel <lars@gustaebel.de>
Fri, 20 Apr 2007 20:10:59 +0000 (20:10 +0000)
committerLars Gustäbel <lars@gustaebel.de>
Fri, 20 Apr 2007 20:10:59 +0000 (20:10 +0000)
argument.

Lib/tarfile.py
Lib/test/test_tarfile.py
Misc/NEWS

index 261d9fbc3620dd96168fce4d386b0f47010741f4..474e306e4c070bd3c6bc836d78e6cb7a51d65f40 100644 (file)
@@ -1044,7 +1044,9 @@ class TarFile(object):
            can be determined, `mode' is overridden by `fileobj's mode.
            `fileobj' is not closed, when TarFile is closed.
         """
-        self.name = os.path.abspath(name)
+        self.name = name
+        if self.name is not None:
+            self.name = os.path.abspath(name)
 
         if len(mode) > 1 or mode not in "raw":
             raise ValueError("mode must be 'r', 'a' or 'w'")
index b1cbcf69c3062c33db8cb93c0d1eb8c1c7437358..dc262f656da105d791704c0a0f00db2975f1405e 100644 (file)
@@ -633,15 +633,21 @@ class FileModeTest(unittest.TestCase):
         self.assertEqual(tarfile.filemode(07111), '---s--s--t')
 
 class OpenFileobjTest(BaseTest):
-    # Test for SF bug #1496501.
 
     def test_opener(self):
+        # Test for SF bug #1496501.
         fobj = StringIO.StringIO("foo\n")
         try:
-            tarfile.open("", "r", fileobj=fobj)
+            tarfile.open("", mode="r", fileobj=fobj)
         except tarfile.ReadError:
             self.assertEqual(fobj.tell(), 0, "fileobj's position has moved")
 
+    def test_fileobj(self):
+        # Test for SF bug #1695229, opening a tarfile without
+        # a name argument.
+        tarfile.open(mode="r", fileobj=open(tarname("")))
+        tarfile.TarFile(mode="r", fileobj=open(tarname("")))
+
 if bz2:
     # Bzip2 TestCases
     class ReadTestBzip2(ReadTestGzip):
index 58f87eac662104064a4731111b8239bdec78b289..450bbce60a0a1338898ccc6a8a434287a71c982d 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -12,6 +12,9 @@ What's New in Python 2.5.2c1?
 Library
 -------
 
+- Patch #1695229: Fix a regression with tarfile.open() and a missing name
+  argument.
+
 - tarfile.py: Fix directory names to have only one trailing slash.