]> granicus.if.org Git - python/commitdiff
Issue #3039: Fix TarFileCompat.writestr() which always raised an
authorLars Gustäbel <lars@gustaebel.de>
Sat, 2 Aug 2008 11:26:39 +0000 (11:26 +0000)
committerLars Gustäbel <lars@gustaebel.de>
Sat, 2 Aug 2008 11:26:39 +0000 (11:26 +0000)
AttributeError since __slots__ were added to zipfile.ZipInfo in
r46967 two years ago.
Add a warning about the removal of TarFileCompat in Python 3.0.

Doc/library/tarfile.rst
Lib/tarfile.py
Misc/NEWS

index b62148aead1382cc2c04c9577ad28eca7de61836..aabd6410bffe8e2a6fd5750d8be2d457f9b2f924 100644 (file)
@@ -140,6 +140,10 @@ Some facts and figures:
       Constant for a :mod:`gzip` compressed tar archive.
 
 
+   .. deprecated:: 2.6
+      The :class:`TarFileCompat` class has been deprecated for removal in Python 3.0.
+
+
 .. exception:: TarError
 
    Base class for all :mod:`tarfile` exceptions.
index 619921328ae646b72e265d1c79dbd8463c2decc5..85abcd8d85020619a34528dd20d9e6ffdd7a6ab6 100644 (file)
@@ -2468,6 +2468,9 @@ class TarFileCompat:
        ZipFile class.
     """
     def __init__(self, file, mode="r", compression=TAR_PLAIN):
+        from warnings import warnpy3k
+        warnpy3k("the TarFileCompat class has been removed in Python 3.0",
+                stacklevel=2)
         if compression == TAR_PLAIN:
             self.tarfile = TarFile.taropen(file, mode)
         elif compression == TAR_GZIPPED:
@@ -2501,10 +2504,10 @@ class TarFileCompat:
         except ImportError:
             from StringIO import StringIO
         import calendar
-        zinfo.name = zinfo.filename
-        zinfo.size = zinfo.file_size
-        zinfo.mtime = calendar.timegm(zinfo.date_time)
-        self.tarfile.addfile(zinfo, StringIO(bytes))
+        tinfo = TarInfo(zinfo.filename)
+        tinfo.size = len(bytes)
+        tinfo.mtime = calendar.timegm(zinfo.date_time)
+        self.tarfile.addfile(tinfo, StringIO(bytes))
     def close(self):
         self.tarfile.close()
 #class TarFileCompat
index 6db54e0e02c422235a61086007d2c3c45a9fd70c..5824ce3279c31fc31ab88b2929eb3a6b72e78355 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -38,6 +38,9 @@ Core and Builtins
 Library
 -------
 
+- Issue #3039: Fix tarfile.TarFileCompat.writestr() which always
+  raised an AttributeError.
+
 - Issue #2523: Fix quadratic behaviour when read()ing a binary file without
   asking for a specific length.