GZ_MAGIC_DEFLATE = struct.pack ("<BBB", GZ_MAGIC [0], GZ_MAGIC [1],
GZ_METHOD_DEFLATE)
+TOLERANCE_STRICT = 0
+TOLERANCE_RECOVER = 1 # rely on offsets in index
+TOLERANCE_RESCUE = 2 # deduce metadata from archive contents
+
#---------------------------------------------------------
# archive handling mode
#---------------------------------------------------------
"""
remainder = -1 # track size in encrypted entries
- tolerant = False
+ tolerance = TOLERANCE_STRICT
def __init__(self, name, mode, comptype, fileobj, bufsize,
concat=False, encryption=None, enccounter=None,
- compresslevel=9, tolerant=False):
+ compresslevel=9, tolerance=TOLERANCE_STRICT):
"""Construct a _Stream object.
"""
self.arcmode = arcmode_set (concat, encryption, comptype)
- self.tolerant = tolerant
+ self.tolerance = tolerance
self._extfileobj = True
if fileobj is None:
try:
return self.encryption.process (buf)
except RuntimeError as exn:
- if self.tolerant is True:
+ if self.tolerance != TOLERANCE_STRICT:
raise DecryptionError (exn)
raise
try:
self._init_read_gz()
except DecryptionError:
- if self.tolerant is True:
+ if self.tolerance != TOLERANCE_STRICT:
# return whatever data was processed successfully
if len (buf) > 0:
t.append (buf)
else:
self.remainder -= todo
except DecryptionError:
- if self.tolerant is False:
+ if self.tolerance == TOLERANCE_STRICT:
raise
self.encryption.drop ()
if good_crypto == 0:
@classmethod
def open(cls, name=None, mode="r", fileobj=None, bufsize=RECORDSIZE,
- encryption=None, compresslevel=9, tolerant=False, **kwargs):
+ encryption=None, compresslevel=9, tolerance=TOLERANCE_STRICT,
+ **kwargs):
"""Open a tar archive for reading, writing or appending. Return
an appropriate TarFile class.
stream = _Stream(name, filemode, comptype, fileobj, bufsize,
concat=True, encryption=encryption,
- compresslevel=compresslevel, tolerant=tolerant)
+ compresslevel=compresslevel, tolerance=tolerance)
kwargs ["concat"] = True
try:
t = cls(name, filemode, stream, **kwargs)