oioioi.base.utils.archive

Module Contents

Classes

Archive

The external API class that encapsulates an archive implementation.

BaseArchive

Base Archive class. Implementations should inherit this class.

TarArchive

Base Archive class. Implementations should inherit this class.

ZipArchive

Base Archive class. Implementations should inherit this class.

Functions

extract(path[, to_path, ext])

Unpack the tar or zip file at the specified path to the directory

Attributes

exception oioioi.base.utils.archive.ArchiveException[source]

Bases: RuntimeError

Base exception class for all archive errors.

exception oioioi.base.utils.archive.UnrecognizedArchiveFormat[source]

Bases: ArchiveException

Error raised when passed file is not a recognized archive format.

exception oioioi.base.utils.archive.UnsafeArchive[source]

Bases: ArchiveException

Error raised when passed file contains paths that would be extracted outside of the target directory.

oioioi.base.utils.archive.extract(path, to_path='', ext='', **kwargs)[source]

Unpack the tar or zip file at the specified path to the directory specified by to_path.

class oioioi.base.utils.archive.Archive(file, ext='')[source]

Bases: object

The external API class that encapsulates an archive implementation.

__del__()[source]
static _resolve_streamed_files(file, ext)[source]
static _archive_cls(file, ext='')[source]

Return the proper Archive implementation class, based on the file type.

extract(*args, **kwargs)[source]
filenames()[source]
dirnames()[source]
extracted_size()[source]
class oioioi.base.utils.archive.BaseArchive[source]

Bases: object

Base Archive class. Implementations should inherit this class.

__del__()[source]
abstract filenames()[source]

Return a list of the filenames contained in the archive.

abstract dirnames()[source]

Return a list of the dirnames contained in the archive.

abstract extracted_size()[source]

Return total file size of extracted files in bytes.

_extract(to_path)[source]

Performs the actual extraction. Separate from ‘extract’ method so that we don’t recurse when subclasses don’t declare their own ‘extract’ method.

extract(to_path='', method='safe')[source]
check_files(to_path=None)[source]

Check that all of the files contained in the archive are within the target directory.

class oioioi.base.utils.archive.TarArchive(file)[source]

Bases: BaseArchive

Base Archive class. Implementations should inherit this class.

filenames()[source]

Return a list of the filenames contained in the archive.

dirnames()[source]

Return a list of the dirnames contained in the archive.

extracted_size()[source]

Return total file size of extracted files in bytes.

check_files(to_path=None)[source]

Check that all of the files contained in the archive are within the target directory.

class oioioi.base.utils.archive.ZipArchive(file)[source]

Bases: BaseArchive

Base Archive class. Implementations should inherit this class.

extracted_size()[source]

Return total file size of extracted files in bytes.

filenames()[source]

Return a list of the filenames contained in the archive.

dirnames()[source]

Return a list of the dirnames contained in the archive.

oioioi.base.utils.archive.extension_map[source]