filetype.filetype module
# -*- coding: utf-8 -*-
from types import types
from match import match
# Expose supported matchers types
types = types
def guess_type(obj):
"""
Infers the type of the given input.
Function is overloaded to accept multiple types in input
and peform the needed type inference based on it.
Args:
obj: path to file, bytes or bytearray.
Returns:
The matched type instance. Otherwise None.
Raises:
TypeError: if obj is not a supported type.
"""
return match(obj) if obj else None
def guess_mime(obj):
"""
Infers the file type of the given input
and returns its MIME type.
Args:
obj: path to file, bytes or bytearray.
Returns:
The matched MIME type as string. Otherwise None.
Raises:
TypeError: if obj is not a supported type.
"""
kind = guess_type(obj)
return kind.mime if kind else kind
def guess_extension(obj):
"""
Infers the file type of the given input
and returns its RFC file extension.
Args:
obj: path to file, bytes or bytearray.
Returns:
The matched file extension as string. Otherwise None.
Raises:
TypeError: if obj is not a supported type.
"""
kind = guess_type(obj)
return kind.extension if kind else kind
def is_extension_supported(ext):
return None
def is_extension_equals(ext):
return None
def is_mime_supported(mime):
return None
def is_mime_equals(mime):
return None
def add_matcher(matcher):
return None
def is_image(instance):
return None
def is_archive(instance):
return None
def is_audio(instance):
return None
def is_video(instance):
return None
def is_font(instance):
return None
def is_type(kind, instance):
return None
Module variables
var types
Functions
def add_matcher(
matcher)
def add_matcher(matcher):
return None
def guess_extension(
obj)
Infers the file type of the given input and returns its RFC file extension.
Args: obj: path to file, bytes or bytearray.
Returns: The matched file extension as string. Otherwise None.
Raises: TypeError: if obj is not a supported type.
def guess_extension(obj):
"""
Infers the file type of the given input
and returns its RFC file extension.
Args:
obj: path to file, bytes or bytearray.
Returns:
The matched file extension as string. Otherwise None.
Raises:
TypeError: if obj is not a supported type.
"""
kind = guess_type(obj)
return kind.extension if kind else kind
def guess_mime(
obj)
Infers the file type of the given input and returns its MIME type.
Args: obj: path to file, bytes or bytearray.
Returns: The matched MIME type as string. Otherwise None.
Raises: TypeError: if obj is not a supported type.
def guess_mime(obj):
"""
Infers the file type of the given input
and returns its MIME type.
Args:
obj: path to file, bytes or bytearray.
Returns:
The matched MIME type as string. Otherwise None.
Raises:
TypeError: if obj is not a supported type.
"""
kind = guess_type(obj)
return kind.mime if kind else kind
def guess_type(
obj)
Infers the type of the given input.
Function is overloaded to accept multiple types in input and peform the needed type inference based on it.
Args: obj: path to file, bytes or bytearray.
Returns: The matched type instance. Otherwise None.
Raises: TypeError: if obj is not a supported type.
def guess_type(obj):
"""
Infers the type of the given input.
Function is overloaded to accept multiple types in input
and peform the needed type inference based on it.
Args:
obj: path to file, bytes or bytearray.
Returns:
The matched type instance. Otherwise None.
Raises:
TypeError: if obj is not a supported type.
"""
return match(obj) if obj else None
def is_archive(
instance)
def is_archive(instance):
return None
def is_audio(
instance)
def is_audio(instance):
return None
def is_extension_equals(
ext)
def is_extension_equals(ext):
return None
def is_extension_supported(
ext)
def is_extension_supported(ext):
return None
def is_font(
instance)
def is_font(instance):
return None
def is_image(
instance)
def is_image(instance):
return None
def is_mime_equals(
mime)
def is_mime_equals(mime):
return None
def is_mime_supported(
mime)
def is_mime_supported(mime):
return None
def is_type(
kind, instance)
def is_type(kind, instance):
return None
def is_video(
instance)
def is_video(instance):
return None