self.exception = zlib.error
self._init_read_gz()
elif mode == "w":
- if self.encryption is None and concat_stream is False:
+ if concat_stream is False and self.encryption is None:
self._init_write_gz ()
self.crc = zlib.crc32(b"") & 0xFFFFffff
raise CompressionError("bad gzip crc")
self.closed = True
+
def _init_read_gz(self):
"""Initialize for reading a gzip compressed fileobj.
"""
if flag & 2:
self.__read(2)
-
def _init_read_encrypt (self):
"""Initialize encryption for next entry in archive. Read a header and
notify the crypto context."""
if self.cmp is not None:
try:
buf = self.cmp.decompress(buf)
- except self.exception:
- raise ReadError("invalid compressed data")
+ except self.exception as exn:
+ raise ReadError("invalid compressed data (%r)" % exn)
except Exception as e:
# happens at the end of the file
# _init_read_gz failed in the previous iteration so
tarinfo = copy.copy(tarinfo)
- if self.concat_compression is True:
+ if self.concat_compression is True and \
+ getattr (self.fileobj, "cmp", None) is not None:
self.fileobj._finalize_write_gz ()
if getattr (self.fileobj, "encryption", None) is not None:
raise Exception("We need to create a new volume and you "
"didn't supply a new_volume_handler")
+
# the new volume handler should do everything needed to
# start working in a new volume. usually, the handler calls
# to self.open_volume
# the “new_volume_handler” is supposed to call .close() on the
# “fileobj” _Stream
self.new_volume_handler(self, self.base_name, self.volume_number)
- if getattr (self.fileobj, "cmp", None) is not None:
+ if self.concat_compression and \
+ getattr (self.fileobj, "cmp", None) is not None:
# e. g. compressed PAX header written
self.fileobj._finalize_write_gz ()
if getattr (self.fileobj, "encryption", None) is not None:
self.fileobj._init_write_encrypt (tarinfo.name)
- if self.concat_compression or \
- getattr (self.fileobj, "cmp", None) is not None:
+ if self.concat_compression is True:
self.fileobj._init_write_gz ()
# write new volume header
buf = self.tarinfo.create_pax_global_header(volume_info.copy())
self.fileobj.write(buf)
self.offset += len(buf)
- except:
+ except Exception as exn:
if not self._extfileobj:
self.fileobj.close()
self.closed = True