Module refinery.units.formats.archive

Expand source code Browse git
from __future__ import annotations

from datetime import datetime

from refinery.lib.types import Callable, Param, buf
from refinery.units import Arg
from refinery.units.formats import PathExtractorUnit, UnpackResult


class MultipleArchives(Exception):
    pass


class ArchiveUnit(PathExtractorUnit, abstract=True):
    def __init__(
        self, *paths, list=False, join_path=False, drop_path=False, fuzzy=0, exact=False, regex=False, path=b'path',
        date: Param[buf, Arg('-D', metavar='NAME',
            help='Name of the meta variable to receive the extracted file date. The default value is "{default}".')] = b'date',
        pwd: Param[buf, Arg('-p', help='Optionally specify an extraction password.')] = B'',
        **kwargs
    ):
        super().__init__(
            *paths,
            list=list,
            join_path=join_path,
            drop_path=drop_path,
            fuzzy=fuzzy,
            exact=exact,
            regex=regex,
            path=path,
            pwd=pwd,
            date=date,
            **kwargs
        )

    _COMMON_PASSWORDS = [
        'infected',
        'virus',
        'malware',
        'dangerous',
        'flare',
        '1234',
        '123',
        'Infected',
        'infected!',
        'INFECTED',
        'notinfected',
        'unzip-me',
        'password',
    ]

    def _pack(
        self,
        path: str,
        date: datetime | str | None,
        data: buf | Callable[[], buf],
        **meta
    ) -> UnpackResult:
        if isinstance(date, datetime):
            date = date.isoformat(' ', 'seconds')
        if isinstance(date, str):
            meta[self.args.date.decode(self.codec)] = date
        return UnpackResult(path, data, **meta)

Sub-modules

refinery.units.formats.archive.innopwd
refinery.units.formats.archive.xt
refinery.units.formats.archive.xt7z
refinery.units.formats.archive.xtace
refinery.units.formats.archive.xtasar
refinery.units.formats.archive.xtcab
refinery.units.formats.archive.xtchm
refinery.units.formats.archive.xtcpio
refinery.units.formats.archive.xtdmp
refinery.units.formats.archive.xtgz
refinery.units.formats.archive.xtinno
refinery.units.formats.archive.xtiso
refinery.units.formats.archive.xtiss
refinery.units.formats.archive.xtmacho
refinery.units.formats.archive.xtmagtape
refinery.units.formats.archive.xtnode
refinery.units.formats.archive.xtnsis
refinery.units.formats.archive.xtnuitka
refinery.units.formats.archive.xtpyi
refinery.units.formats.archive.xtrpa
refinery.units.formats.archive.xtsim
refinery.units.formats.archive.xtsql
refinery.units.formats.archive.xttar
refinery.units.formats.archive.xtzip
refinery.units.formats.archive.xtzpaq

This code was ported directly from unzpaq.cpp; it is not very Pythonic and has inherited a somewhat convoluted structure from the source. Cleaning it …

Classes

class MultipleArchives (*args, **kwargs)

Common base class for all non-exit exceptions.

Expand source code Browse git
class MultipleArchives(Exception):
    pass

Ancestors

  • builtins.Exception
  • builtins.BaseException
class ArchiveUnit (*paths, list=False, join_path=False, drop_path=False, fuzzy=0, exact=False, regex=False, path=b'path', date=b'date', pwd=b'', **kwargs)
Expand source code Browse git
class ArchiveUnit(PathExtractorUnit, abstract=True):
    def __init__(
        self, *paths, list=False, join_path=False, drop_path=False, fuzzy=0, exact=False, regex=False, path=b'path',
        date: Param[buf, Arg('-D', metavar='NAME',
            help='Name of the meta variable to receive the extracted file date. The default value is "{default}".')] = b'date',
        pwd: Param[buf, Arg('-p', help='Optionally specify an extraction password.')] = B'',
        **kwargs
    ):
        super().__init__(
            *paths,
            list=list,
            join_path=join_path,
            drop_path=drop_path,
            fuzzy=fuzzy,
            exact=exact,
            regex=regex,
            path=path,
            pwd=pwd,
            date=date,
            **kwargs
        )

    _COMMON_PASSWORDS = [
        'infected',
        'virus',
        'malware',
        'dangerous',
        'flare',
        '1234',
        '123',
        'Infected',
        'infected!',
        'INFECTED',
        'notinfected',
        'unzip-me',
        'password',
    ]

    def _pack(
        self,
        path: str,
        date: datetime | str | None,
        data: buf | Callable[[], buf],
        **meta
    ) -> UnpackResult:
        if isinstance(date, datetime):
            date = date.isoformat(' ', 'seconds')
        if isinstance(date, str):
            meta[self.args.date.decode(self.codec)] = date
        return UnpackResult(path, data, **meta)

Ancestors

Subclasses

Inherited members