filetype.match module
# -*- coding: utf-8 -*- from .utils import get_bytes from .types import ( types, image as image_matchers, video as video_matchers, font as font_matchers, archive as archive_matchers, audio as audio_matchers ) def match(obj, matchers=types): """ Matches the given input againts the available file type matchers. Args: obj: path to file, bytes or bytearray. Returns: Type instance if type matches. Otherwise None. Raises: TypeError: if obj is not a supported type. """ buf = get_bytes(obj) for matcher in matchers: if matcher.match(buf): return matcher return None def image(obj): """ Matches the given input againts the available image type matchers. Args: obj: path to file, bytes or bytearray. Returns: Type instance if matches. Otherwise None. Raises: TypeError: if obj is not a supported type. """ return match(obj, image_matchers) def font(obj): """ Matches the given input againts the available font type matchers. Args: obj: path to file, bytes or bytearray. Returns: Type instance if matches. Otherwise None. Raises: TypeError: if obj is not a supported type. """ return match(obj, font_matchers) def video(obj): """ Matches the given input againts the available video type matchers. Args: obj: path to file, bytes or bytearray. Returns: Type instance if matches. Otherwise None. Raises: TypeError: if obj is not a supported type. """ return match(obj, video_matchers) def audio(obj): """ Matches the given input againts the available autio type matchers. Args: obj: path to file, bytes or bytearray. Returns: Type instance if matches. Otherwise None. Raises: TypeError: if obj is not a supported type. """ return match(obj, audio_matchers) def archive(obj): """ Matches the given input againts the available archive type matchers. Args: obj: path to file, bytes or bytearray. Returns: Type instance if matches. Otherwise None. Raises: TypeError: if obj is not a supported type. """ return match(obj, archive_matchers)
Module variables
var archive_matchers
var audio_matchers
var font_matchers
var image_matchers
var types
var video_matchers
Functions
def archive(
obj)
Matches the given input againts the available archive type matchers.
Args: obj: path to file, bytes or bytearray.
Returns: Type instance if matches. Otherwise None.
Raises: TypeError: if obj is not a supported type.
def archive(obj): """ Matches the given input againts the available archive type matchers. Args: obj: path to file, bytes or bytearray. Returns: Type instance if matches. Otherwise None. Raises: TypeError: if obj is not a supported type. """ return match(obj, archive_matchers)
def audio(
obj)
Matches the given input againts the available autio type matchers.
Args: obj: path to file, bytes or bytearray.
Returns: Type instance if matches. Otherwise None.
Raises: TypeError: if obj is not a supported type.
def audio(obj): """ Matches the given input againts the available autio type matchers. Args: obj: path to file, bytes or bytearray. Returns: Type instance if matches. Otherwise None. Raises: TypeError: if obj is not a supported type. """ return match(obj, audio_matchers)
def font(
obj)
Matches the given input againts the available font type matchers.
Args: obj: path to file, bytes or bytearray.
Returns: Type instance if matches. Otherwise None.
Raises: TypeError: if obj is not a supported type.
def font(obj): """ Matches the given input againts the available font type matchers. Args: obj: path to file, bytes or bytearray. Returns: Type instance if matches. Otherwise None. Raises: TypeError: if obj is not a supported type. """ return match(obj, font_matchers)
def image(
obj)
Matches the given input againts the available image type matchers.
Args: obj: path to file, bytes or bytearray.
Returns: Type instance if matches. Otherwise None.
Raises: TypeError: if obj is not a supported type.
def image(obj): """ Matches the given input againts the available image type matchers. Args: obj: path to file, bytes or bytearray. Returns: Type instance if matches. Otherwise None. Raises: TypeError: if obj is not a supported type. """ return match(obj, image_matchers)
def match(
obj, matchers=[<filetype.types.image.Jpeg object at 0x10f109350>, <filetype.types.image.Png object at 0x10f109390>, <filetype.types.image.Gif object at 0x10f1093d0>, <filetype.types.image.Webp object at 0x10f109410>, <filetype.types.image.Cr2 object at 0x10f109450>, <filetype.types.image.Tiff object at 0x10f109490>, <filetype.types.image.Bmp object at 0x10f1094d0>, <filetype.types.image.Jxr object at 0x10f109510>, <filetype.types.image.Psd object at 0x10f109550>, <filetype.types.image.Ico object at 0x10f109590>, <filetype.types.audio.Midi object at 0x10f109790>, <filetype.types.audio.Mp3 object at 0x10f1097d0>, <filetype.types.audio.M4a object at 0x10f109810>, <filetype.types.audio.Ogg object at 0x10f109850>, <filetype.types.audio.Flac object at 0x10f109890>, <filetype.types.audio.Wav object at 0x10f1098d0>, <filetype.types.audio.Amr object at 0x10f109910>, <filetype.types.font.Woff object at 0x10f109950>, <filetype.types.font.Woff2 object at 0x10f109990>, <filetype.types.font.Ttf object at 0x10f1099d0>, <filetype.types.font.Otf object at 0x10f109a10>, <filetype.types.video.Mp4 object at 0x10f1095d0>, <filetype.types.video.M4v object at 0x10f109610>, <filetype.types.video.Mkv object at 0x10f109650>, <filetype.types.video.Mov object at 0x10f109690>, <filetype.types.video.Avi object at 0x10f1096d0>, <filetype.types.video.Wmv object at 0x10f109710>, <filetype.types.video.Mpeg object at 0x10f109750>, <filetype.types.archive.Epub object at 0x10f109a50>, <filetype.types.archive.Zip object at 0x10f109a90>, <filetype.types.archive.Tar object at 0x10f109ad0>, <filetype.types.archive.Rar object at 0x10f109b10>, <filetype.types.archive.Gz object at 0x10f109b50>, <filetype.types.archive.Bz2 object at 0x10f109b90>, <filetype.types.archive.SevenZ object at 0x10f109bd0>, <filetype.types.archive.Pdf object at 0x10f109c10>, <filetype.types.archive.Exe object at 0x10f109c50>, <filetype.types.archive.Swf object at 0x10f109c90>, <filetype.types.archive.Rtf object at 0x10f109cd0>, <filetype.types.archive.Nes object at 0x10f109d10>, <filetype.types.archive.Crx object at 0x10f109d50>, <filetype.types.archive.Cab object at 0x10f109d90>, <filetype.types.archive.Eot object at 0x10f109dd0>, <filetype.types.archive.Ps object at 0x10f109e10>, <filetype.types.archive.Xz object at 0x10f109e50>, <filetype.types.archive.Sqlite object at 0x10f109e90>, <filetype.types.archive.Deb object at 0x10f109ed0>, <filetype.types.archive.Ar object at 0x10f109f10>, <filetype.types.archive.Z object at 0x10f109f50>, <filetype.types.archive.Lz object at 0x10f109f90>])
Matches the given input againts the available file type matchers.
Args: obj: path to file, bytes or bytearray.
Returns: Type instance if type matches. Otherwise None.
Raises: TypeError: if obj is not a supported type.
def match(obj, matchers=types): """ Matches the given input againts the available file type matchers. Args: obj: path to file, bytes or bytearray. Returns: Type instance if type matches. Otherwise None. Raises: TypeError: if obj is not a supported type. """ buf = get_bytes(obj) for matcher in matchers: if matcher.match(buf): return matcher return None
def video(
obj)
Matches the given input againts the available video type matchers.
Args: obj: path to file, bytes or bytearray.
Returns: Type instance if matches. Otherwise None.
Raises: TypeError: if obj is not a supported type.
def video(obj): """ Matches the given input againts the available video type matchers. Args: obj: path to file, bytes or bytearray. Returns: Type instance if matches. Otherwise None. Raises: TypeError: if obj is not a supported type. """ return match(obj, video_matchers)