πŸ—ƒ file_types moduleΒΆ

Operations of file and mime type discovery, based on file content.

class pupyl.duplex.file_types.FileHeaderHex(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)ΒΆ

Describes header hexadecimals for every supported file types.

The current ones supported are:

JPG, GIF, PNG, TIF, GZP, BZ2, ZIP, LXZ

class pupyl.duplex.file_types.FileMimeTypes(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)ΒΆ

Describes the mime types associated with underlying files.

The current ones supported are:

JPG, GIF, PNG, TIF, GZP, BZ2, ZIP, LXZ

class pupyl.duplex.file_types.FileTypeΒΆ

Operations of file type discovery over file content.

classmethod guess_file_type(bytess, mimetype=False)ΒΆ

Heuristically discover the file type for the underlying path.

Parameters:
  • bytess (bytes) – Bytes of some file.

  • mimetype (bool) – If the mimetype should be returned or not.

Raises:

FileTypeNotSupportedYet: – For an unsupported file.

Returns:

With inferred type.

Return type:

str

classmethod header(bytess)ΒΆ

Return only the file header or the first three bytes.

Parameters:

bytess (bytes) – Bytes of some file.

Returns:

With the header hexadecimal representation.

Return type:

str

classmethod is_image(bytess)ΒΆ

Return if the read file is an image or not.

Parameters:

bytess (bytes) – Bytes of some file

Raises:

FileTypeNotSupportedYet: – For an unsupported file.

Returns:

Describing if the inferred type is image

Return type:

bool

static tar_compressed_types_resolve(sub_type, mimetype=False)ΒΆ

Resolves a tar file compression type (if any).

Parameters:
  • sub_type (str) – The sub type of the tar compressed type.

  • mimetype (bool) – If should be returned the MIME type instead of internal file type name.

Returns:

With inferred tar (compressed) type

Return type:

str

static to_hex(bytess)ΒΆ

Converts a byte string to its hexadecimal representation.

Parameters:

bytess (bytes) – Bytes of some file

Returns:

With the hexadecimal representation

Return type:

str

class pupyl.duplex.file_types.TarCompressedTypesΒΆ

Describes all supported tar compressed types.

The current ones supported are:

GZIP, LZMA, BZIP2

classmethod mime(sub_type)ΒΆ

Return the mime type of some sub type.

Parameters:

sub_type (str) – The name of one subtype.

Returns:

With the found subtype mimetype.

Return type:

str

Example

TarCompressedTypes.name('xz') # Returns 'application/tar-xz'

classmethod name(sub_type)ΒΆ

Returns the name of some sub (file) type.

Parameters:

sub_type (str) – The name of one subtype.

Returns:

With the found subtype.

Return type:

str

Example

TarCompressedTypes.name('xz') # Returns 'TXZ'