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 0x10d5e50d0>, <filetype.types.image.Png object at 0x10d5e5110>, <filetype.types.image.Gif object at 0x10d5e5150>, <filetype.types.image.Webp object at 0x10d5e5190>, <filetype.types.image.Cr2 object at 0x10d5e51d0>, <filetype.types.image.Tiff object at 0x10d5e5210>, <filetype.types.image.Bmp object at 0x10d5e5250>, <filetype.types.image.Jxr object at 0x10d5e5290>, <filetype.types.image.Psd object at 0x10d5e52d0>, <filetype.types.image.Ico object at 0x10d5e5310>, <filetype.types.audio.Midi object at 0x10d5e5510>, <filetype.types.audio.Mp3 object at 0x10d5e5550>, <filetype.types.audio.M4a object at 0x10d5e5590>, <filetype.types.audio.Ogg object at 0x10d5e55d0>, <filetype.types.audio.Flac object at 0x10d5e5610>, <filetype.types.audio.Wav object at 0x10d5e5650>, <filetype.types.audio.Amr object at 0x10d5e5690>, <filetype.types.font.Woff object at 0x10d5e56d0>, <filetype.types.font.Woff2 object at 0x10d5e5710>, <filetype.types.font.Ttf object at 0x10d5e5750>, <filetype.types.font.Otf object at 0x10d5e5790>, <filetype.types.video.Mp4 object at 0x10d5e5350>, <filetype.types.video.M4v object at 0x10d5e5390>, <filetype.types.video.Mkv object at 0x10d5e53d0>, <filetype.types.video.Mov object at 0x10d5e5410>, <filetype.types.video.Avi object at 0x10d5e5450>, <filetype.types.video.Wmv object at 0x10d5e5490>, <filetype.types.video.Mpeg object at 0x10d5e54d0>, <filetype.types.archive.Epub object at 0x10d5e57d0>, <filetype.types.archive.Zip object at 0x10d5e5810>, <filetype.types.archive.Tar object at 0x10d5e5850>, <filetype.types.archive.Rar object at 0x10d5e5890>, <filetype.types.archive.Gz object at 0x10d5e58d0>, <filetype.types.archive.Bz2 object at 0x10d5e5910>, <filetype.types.archive.SevenZ object at 0x10d5e5950>, <filetype.types.archive.Pdf object at 0x10d5e5990>, <filetype.types.archive.Exe object at 0x10d5e59d0>, <filetype.types.archive.Swf object at 0x10d5e5a10>, <filetype.types.archive.Rtf object at 0x10d5e5a50>, <filetype.types.archive.Nes object at 0x10d5e5a90>, <filetype.types.archive.Crx object at 0x10d5e5ad0>, <filetype.types.archive.Cab object at 0x10d5e5b10>, <filetype.types.archive.Eot object at 0x10d5e5b50>, <filetype.types.archive.Ps object at 0x10d5e5b90>, <filetype.types.archive.Xz object at 0x10d5e5bd0>, <filetype.types.archive.Sqlite object at 0x10d5e5c10>, <filetype.types.archive.Deb object at 0x10d5e5c50>, <filetype.types.archive.Ar object at 0x10d5e5c90>, <filetype.types.archive.Z object at 0x10d5e5cd0>, <filetype.types.archive.Lz object at 0x10d5e5d10>])
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)