Package: python2.7 Severity: wishlist Tags: patch Currently Debian patch tracker uses python 2 and fails to open *.debian.tar.xz, see for example:
http://patch-tracker.debian.org/package/sbcl/2:1.1.15-1 I've made quick and dirty backport of tarfile from python3. Tested only with patch tracker: http://patches.osdyson.org/package/sbcl/2:1.1.15-1+dyson1 --- System information. --- Architecture: amd64 Kernel: Linux 3.10-2-amd64 Debian Release: jessie/sid 500 unstable mirror.yandex.ru 500 testing security.debian.org 500 testing mirror.yandex.ru 500 stable sdkrepo.atlassian.com --- Package information. --- Depends (Version) | Installed ===================================-+-============ python2.7-minimal (= 2.7.6-5) | 2.7.6-5 libpython2.7-stdlib (= 2.7.6-5) | 2.7.6-5 mime-support | 3.54 Package's Recommends field is empty. Suggests (Version) | Installed ============================-+-=========== python2.7-doc | binutils | 2.24-5
--- /usr/lib/python2.7/tarfile.py.orig 2014-04-22 09:04:41.000000000 +0100 +++ /usr/lib/python2.7/tarfile.py 2014-04-22 09:10:53.000000000 +0100 @@ -440,6 +440,19 @@ else: self.cmp = bz2.BZ2Compressor() + if comptype == "xz": + try: + import lzma + except ImportError: + raise CompressionError("lzma module is not available") + if mode == "r": + self.dbuf = b"" + self.cmp = lzma.LZMADecompressor() + self.exception = lzma.LZMAError + else: + self.cmp = lzma.LZMACompressor() + + def __del__(self): if hasattr(self, "closed") and not self.closed: self.close() @@ -1759,11 +1772,37 @@ t._extfileobj = False return t + @classmethod + def xzopen(cls, name, mode="r", fileobj=None, compresslevel=9, **kwargs): + """Open lzma compressed tar archive name for reading or writing. + Appending is not allowed. + """ + if mode not in ("r", "w"): + raise ValueError("mode must be 'r' or 'w'") + + try: + import lzma + except ImportError: + raise CompressionError("lzma module is not available") + + fileobj = lzma.LZMAFile(fileobj or name, mode) + + try: + t = cls.taropen(name, mode, fileobj, **kwargs) + except (lzma.LZMAError, EOFError): + fileobj.close() + raise ReadError("not an lzma file") + t._extfileobj = False + return t + + # All *open() methods are registered here. OPEN_METH = { "tar": "taropen", # uncompressed tar "gz": "gzopen", # gzip compressed tar - "bz2": "bz2open" # bzip2 compressed tar + "bz2": "bz2open", # bzip2 compressed tar + "xz": "xzopen" # lzma compressed tar + } #--------------------------------------------------------------------------