Exemplo n.º 1
0
 def _archive_cls(file, ext=''):
     """
     Return the proper Archive implementation class, based on the file type.
     """
     cls = None
     filename = None
     if is_string(file):
         filename = file
     else:
         try:
             filename = file.name
         except AttributeError:
             raise UnrecognizedArchiveFormat(
                 "File object not a recognized archive format.")
     lookup_filename = filename + ext
     base, tail_ext = os.path.splitext(lookup_filename.lower())
     cls = extension_map.get(tail_ext)
     if not cls:
         base, ext = os.path.splitext(base)
         cls = extension_map.get(ext)
     if not cls:
         raise UnrecognizedArchiveFormat(
             "Path not a recognized archive format: %s" % filename)
     return cls
 def _archive_cls(file, ext=''):
     """
     Return the proper Archive implementation class, based on the file type.
     """
     cls = None
     filename = None
     if is_string(file):
         filename = file
     else:
         try:
             filename = file.name
         except AttributeError:
             raise UnrecognizedArchiveFormat(
                 "File object not a recognized archive format.")
     lookup_filename = filename + ext
     base, tail_ext = os.path.splitext(lookup_filename.lower())
     cls = extension_map.get(tail_ext)
     if not cls:
         base, ext = os.path.splitext(base)
         cls = extension_map.get(ext)
     if not cls:
         raise UnrecognizedArchiveFormat(
             "Path not a recognized archive format: %s" % filename)
     return cls
Exemplo n.º 3
0
 def __init__(self, file):
     # tarfile's open uses different parameters for file path vs. file obj.
     if is_string(file):
         self._archive = tarfile.open(name=file)
     else:
         self._archive = tarfile.open(fileobj=file)
 def __init__(self, file):
     # tarfile's open uses different parameters for file path vs. file obj.
     if is_string(file):
         self._archive = tarfile.open(name=file)
     else:
         self._archive = tarfile.open(fileobj=file)