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 0x10c5b5cd0>, <filetype.types.image.Png object at 0x10c5b5c50>, <filetype.types.image.Gif object at 0x10c5b5d10>, <filetype.types.image.Webp object at 0x10c5b5bd0>, <filetype.types.image.Cr2 object at 0x10c5b5b50>, <filetype.types.image.Tiff object at 0x10c5b5ad0>, <filetype.types.image.Bmp object at 0x10c5b5b90>, <filetype.types.image.Jxr object at 0x10c5b5a10>, <filetype.types.image.Psd object at 0x10c5b5490>, <filetype.types.image.Ico object at 0x10c5b5a50>, <filetype.types.audio.Midi object at 0x10c5c2b10>, <filetype.types.audio.Mp3 object at 0x10c5c2a90>, <filetype.types.audio.M4a object at 0x10c5c2b50>, <filetype.types.audio.Ogg object at 0x10c5c29d0>, <filetype.types.audio.Flac object at 0x10c5c2950>, <filetype.types.audio.Wav object at 0x10c5c2a10>, <filetype.types.audio.Amr object at 0x10c5c2850>, <filetype.types.font.Woff object at 0x10c5c27d0>, <filetype.types.font.Woff2 object at 0x10c5c2890>, <filetype.types.font.Ttf object at 0x10c5c26d0>, <filetype.types.font.Otf object at 0x10c5c2650>, <filetype.types.video.Mp4 object at 0x10c5b5210>, <filetype.types.video.M4v object at 0x10c5b5190>, <filetype.types.video.Mkv object at 0x10c5b53d0>, <filetype.types.video.Mov object at 0x10c5b5550>, <filetype.types.video.Avi object at 0x10c5b5610>, <filetype.types.video.Wmv object at 0x10c5b5090>, <filetype.types.video.Mpeg object at 0x10c5c2b90>, <filetype.types.archive.Epub object at 0x10c5c2710>, <filetype.types.archive.Zip object at 0x10c5c2590>, <filetype.types.archive.Tar object at 0x10c5c2510>, <filetype.types.archive.Rar object at 0x10c5c25d0>, <filetype.types.archive.Gz object at 0x10c5c2410>, <filetype.types.archive.Bz2 object at 0x10c5c2390>, <filetype.types.archive.SevenZ object at 0x10c5c2450>, <filetype.types.archive.Pdf object at 0x10c5c22d0>, <filetype.types.archive.Exe object at 0x10c5c2250>, <filetype.types.archive.Swf object at 0x10c5c2310>, <filetype.types.archive.Rtf object at 0x10c5c2110>, <filetype.types.archive.Nes object at 0x10c5c2090>, <filetype.types.archive.Crx object at 0x10c5c2190>, <filetype.types.archive.Cab object at 0x10c5c2bd0>, <filetype.types.archive.Eot object at 0x10c5c2c10>, <filetype.types.archive.Ps object at 0x10c5c2c50>, <filetype.types.archive.Xz object at 0x10c5c2c90>, <filetype.types.archive.Sqlite object at 0x10c5c2cd0>, <filetype.types.archive.Deb object at 0x10c5c2d10>, <filetype.types.archive.Ar object at 0x10c5c2d50>, <filetype.types.archive.Z object at 0x10c5c2d90>, <filetype.types.archive.Lz object at 0x10c5c2dd0>])
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)