[Python-checkins] r57616 - in python/trunk: Lib/tarfile.py Lib/test/test_tarfile.py Misc/NEWS
lars.gustaebel
python-checkins at python.org
Tue Aug 28 14:31:10 CEST 2007
Author: lars.gustaebel
Date: Tue Aug 28 14:31:09 2007
New Revision: 57616
Modified:
python/trunk/Lib/tarfile.py
python/trunk/Lib/test/test_tarfile.py
python/trunk/Misc/NEWS
Log:
TarFile.__init__() no longer fails if no name argument is passed and
the fileobj argument has no usable name attribute (e.g. StringIO).
(will backport to 2.5)
Modified: python/trunk/Lib/tarfile.py
==============================================================================
--- python/trunk/Lib/tarfile.py (original)
+++ python/trunk/Lib/tarfile.py Tue Aug 28 14:31:09 2007
@@ -1522,7 +1522,7 @@
if hasattr(fileobj, "mode"):
self._mode = fileobj.mode
self._extfileobj = True
- self.name = os.path.abspath(name)
+ self.name = os.path.abspath(name) if name else None
self.fileobj = fileobj
# Init attributes.
Modified: python/trunk/Lib/test/test_tarfile.py
==============================================================================
--- python/trunk/Lib/test/test_tarfile.py (original)
+++ python/trunk/Lib/test/test_tarfile.py Tue Aug 28 14:31:09 2007
@@ -141,11 +141,25 @@
class MiscReadTest(ReadTest):
- def test_no_filename(self):
+ def test_no_name_argument(self):
fobj = open(self.tarname, "rb")
tar = tarfile.open(fileobj=fobj, mode=self.mode)
self.assertEqual(tar.name, os.path.abspath(fobj.name))
+ def test_no_name_attribute(self):
+ data = open(self.tarname, "rb").read()
+ fobj = StringIO.StringIO(data)
+ self.assertRaises(AttributeError, getattr, fobj, "name")
+ tar = tarfile.open(fileobj=fobj, mode=self.mode)
+ self.assertEqual(tar.name, None)
+
+ def test_empty_name_attribute(self):
+ data = open(self.tarname, "rb").read()
+ fobj = StringIO.StringIO(data)
+ fobj.name = ""
+ tar = tarfile.open(fileobj=fobj, mode=self.mode)
+ self.assertEqual(tar.name, None)
+
def test_fail_comp(self):
# For Gzip and Bz2 Tests: fail with a ReadError on an uncompressed file.
if self.mode == "r:":
Modified: python/trunk/Misc/NEWS
==============================================================================
--- python/trunk/Misc/NEWS (original)
+++ python/trunk/Misc/NEWS Tue Aug 28 14:31:09 2007
@@ -240,6 +240,9 @@
Library
-------
+- TarFile.__init__() no longer fails if no name argument is passed and
+ the fileobj argument has no usable name attribute (e.g. StringIO).
+
- The functools module now provides 'reduce', for forward compatibility
with Python 3000.
More information about the Python-checkins
mailing list