Pass on 'compresslevel' for gzip / bzip2 compressed archives only
authorThomas Jarosch <thomas.jarosch@intra2net.com>
Fri, 3 Jul 2015 14:35:57 +0000 (16:35 +0200)
committerThomas Jarosch <thomas.jarosch@intra2net.com>
Fri, 3 Jul 2015 14:38:46 +0000 (16:38 +0200)
Otherwise we crash when opening plain tar files for writing:

    TypeError: taropen() takes from 2 to 4 positional arguments but 5 were given

First part of the unit test fix. Verified with debug statements
in gzopen() that passing on the parameter still works.

deltatar/tarfile.py

index 356b154..729079f 100644 (file)
@@ -1908,7 +1908,12 @@ class TarFile(object):
                 func = getattr(cls, cls.OPEN_METH[comptype])
             else:
                 raise CompressionError("unknown compression type %r" % comptype)
-            return func(name, filemode, fileobj, compresslevel, **kwargs)
+
+            # Pass on compression level for gzip / bzip2.
+            if comptype == 'gz' or comptype == 'bz2':
+                kwargs['compresslevel'] = compresslevel
+
+            return func(name, filemode, fileobj, **kwargs)
 
         elif "|" in mode:
             filemode, comptype = mode.split("|", 1)