filetype.match module
# -*- coding: utf-8 -*- from __future__ import absolute_import from .types import ARCHIVE as archive_matchers from .types import AUDIO as audio_matchers from .types import FONT as font_matchers from .types import IMAGE as image_matchers from .types import VIDEO as video_matchers from .types import TYPES from .utils import get_bytes 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 TYPES
var archive_matchers
var audio_matchers
var font_matchers
var image_matchers
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 0x10de8b750>, <filetype.types.image.Png object at 0x10de8b790>, <filetype.types.image.Gif object at 0x10de8b7d0>, <filetype.types.image.Webp object at 0x10de8b810>, <filetype.types.image.Cr2 object at 0x10de8b850>, <filetype.types.image.Tiff object at 0x10de8b890>, <filetype.types.image.Bmp object at 0x10de8b8d0>, <filetype.types.image.Jxr object at 0x10de8b910>, <filetype.types.image.Psd object at 0x10de8b950>, <filetype.types.image.Ico object at 0x10de8b990>, <filetype.types.audio.Midi object at 0x10de8bb90>, <filetype.types.audio.Mp3 object at 0x10de8bbd0>, <filetype.types.audio.M4a object at 0x10de8bc10>, <filetype.types.audio.Ogg object at 0x10de8bc50>, <filetype.types.audio.Flac object at 0x10de8bc90>, <filetype.types.audio.Wav object at 0x10de8bcd0>, <filetype.types.audio.Amr object at 0x10de8bd10>, <filetype.types.font.Woff object at 0x10de8bd50>, <filetype.types.font.Woff2 object at 0x10de8bd90>, <filetype.types.font.Ttf object at 0x10de8bdd0>, <filetype.types.font.Otf object at 0x10de8be10>, <filetype.types.video.Mp4 object at 0x10de8b9d0>, <filetype.types.video.M4v object at 0x10de8ba10>, <filetype.types.video.Mkv object at 0x10de8ba50>, <filetype.types.video.Mov object at 0x10de8ba90>, <filetype.types.video.Avi object at 0x10de8bad0>, <filetype.types.video.Wmv object at 0x10de8bb10>, <filetype.types.video.Mpeg object at 0x10de8bb50>, <filetype.types.archive.Epub object at 0x10de8be50>, <filetype.types.archive.Zip object at 0x10de8be90>, <filetype.types.archive.Tar object at 0x10de8bed0>, <filetype.types.archive.Rar object at 0x10de8bf10>, <filetype.types.archive.Gz object at 0x10de8bf50>, <filetype.types.archive.Bz2 object at 0x10de8bf90>, <filetype.types.archive.SevenZ object at 0x10de8bfd0>, <filetype.types.archive.Pdf object at 0x10de95050>, <filetype.types.archive.Exe object at 0x10de95090>, <filetype.types.archive.Swf object at 0x10de950d0>, <filetype.types.archive.Rtf object at 0x10de95110>, <filetype.types.archive.Nes object at 0x10de95150>, <filetype.types.archive.Crx object at 0x10de95190>, <filetype.types.archive.Cab object at 0x10de951d0>, <filetype.types.archive.Eot object at 0x10de95210>, <filetype.types.archive.Ps object at 0x10de95250>, <filetype.types.archive.Xz object at 0x10de95290>, <filetype.types.archive.Sqlite object at 0x10de952d0>, <filetype.types.archive.Deb object at 0x10de95310>, <filetype.types.archive.Ar object at 0x10de95350>, <filetype.types.archive.Z object at 0x10de95390>, <filetype.types.archive.Lz object at 0x10de953d0>])
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)