Example #1
0
def unpack(filepath=None,
           contents=None,
           password=None,
           filename=None,
           duplicates=None):
    """Unpacks the file or contents provided."""
    if duplicates is None:
        duplicates = []

    if six.PY3:
        if isinstance(filepath, str) or isinstance(contents, str):
            raise IncorrectUsageException

        if isinstance(filename, str):
            raise IncorrectUsageException

    if contents:
        f = File(filepath, contents, filename=filename)
    else:
        f = File.from_path(filepath, filename=filename)

    Unpacker.single(f, password, duplicates)

    ident(f)
    return f
Example #2
0
def unpack(filepath,
           contents=None,
           password=None,
           filename=None,
           duplicates=None):
    """Unpacks the file or contents provided."""
    if contents:
        f = File(filepath, contents, filename=filename)
    else:
        f = File.from_path(filepath, filename=filename)

    if duplicates is None:
        duplicates = []

    # Determine how we're going to unpack this file (if at all). It may not
    # have a file extension, e.g., when its filename is a hash. In those cases
    # we're going to take a look at the contents of the file.
    f.unpacker = Unpacker.guess(f)

    # Actually unpack any embedded files in this archive.
    if f.unpacker:
        plugin = plugins[f.unpacker](f)
        if plugin.supported():
            f.children = plugin.unpack(password, duplicates)

    return f
Example #3
0
def unpack(filepath=None,
           contents=None,
           password=None,
           filename=None,
           duplicates=None):
    """Unpacks the file or contents provided."""
    if duplicates is None:
        duplicates = []

    if contents:
        f = File(filepath, contents, filename=filename)
    else:
        f = File.from_path(filepath, filename=filename)

    Unpacker.single(f, password, duplicates)

    ident(f)
    return f
Example #4
0
def unpack(filepath=None, contents=None, password=None, filename=None,
           duplicates=None):
    """Unpacks the file or contents provided."""
    if contents:
        f = File(filepath, contents, filename=filename)
    else:
        f = File.from_path(filepath, filename=filename)

    if duplicates is None:
        duplicates = []

    # Determine how we're going to unpack this file (if at all). It may not
    # have a file extension, e.g., when its filename is a hash. In those cases
    # we're going to take a look at the contents of the file.
    f.unpacker = Unpacker.guess(f)

    # Actually unpack any embedded files in this archive.
    if f.unpacker:
        plugin = plugins[f.unpacker](f)
        if plugin.supported():
            f.children = plugin.unpack(password, duplicates)

    return f
Example #5
0
def guess(file):
    return sorted(list(Unpacker.guess(file)))
Example #6
0
def guess(filename):
    return sorted(list(Unpacker.guess(File(filename=filename))))
Example #7
0
def test_extensions():
    assert Unpacker.guess(File(filename="a.tar")) == "tarfile"
    assert Unpacker.guess(File(filename="a.tar.gz")) == "targzfile"
    assert Unpacker.guess(File(filename="a.tar.bz2")) == "tarbz2file"
    assert Unpacker.guess(File(filename="a.zip")) == "zipfile"
    assert Unpacker.guess(File(filename="a.rar")) == "rarfile"
    assert Unpacker.guess(File(filename="a.7z")) == "7zfile"
    assert Unpacker.guess(File(filename="a.ace")) == "acefile"
    assert Unpacker.guess(File(filename="a.eml")) == "emlfile"
    assert Unpacker.guess(File(filename="a.msg")) == "msgfile"
    assert Unpacker.guess(File(filename="a.mso")) == "msofile"
    assert Unpacker.guess(File(filename="a.bup")) == "bupfile"
Example #8
0
def test_case():
    assert Unpacker.guess(File(filename="A.ZIP")) == "zipfile"
Example #9
0
def test_extensions():
    assert Unpacker.guess(File(filename="a.tar")) == "tarfile"
    assert Unpacker.guess(File(filename="a.tar.gz")) == "targzfile"
    assert Unpacker.guess(File(filename="a.tar.bz2")) == "tarbz2file"
    assert Unpacker.guess(File(filename="a.zip")) == "zipfile"
    assert Unpacker.guess(File(filename="a.rar")) == "rarfile"
    assert Unpacker.guess(File(filename="a.7z")) == "7zfile"
    assert Unpacker.guess(File(filename="a.ace")) == "acefile"
    assert Unpacker.guess(File(filename="a.eml")) == "emlfile"
    assert Unpacker.guess(File(filename="a.msg")) == "msgfile"
    assert Unpacker.guess(File(filename="a.mso")) == "msofile"
    assert Unpacker.guess(File(filename="a.bup")) == "bupfile"
Example #10
0
def test_case():
    assert Unpacker.guess(File(filename="A.ZIP")) == "zipfile"