about summary refs log tree commit diff
path: root/.venv/lib/python3.12/site-packages/filetype/helpers.py
diff options
context:
space:
mode:
authorS. Solomon Darnell2025-03-28 21:52:21 -0500
committerS. Solomon Darnell2025-03-28 21:52:21 -0500
commit4a52a71956a8d46fcb7294ac71734504bb09bcc2 (patch)
treeee3dc5af3b6313e921cd920906356f5d4febc4ed /.venv/lib/python3.12/site-packages/filetype/helpers.py
parentcc961e04ba734dd72309fb548a2f97d67d578813 (diff)
downloadgn-ai-master.tar.gz
two version of R2R are here HEAD master
Diffstat (limited to '.venv/lib/python3.12/site-packages/filetype/helpers.py')
-rw-r--r--.venv/lib/python3.12/site-packages/filetype/helpers.py140
1 files changed, 140 insertions, 0 deletions
diff --git a/.venv/lib/python3.12/site-packages/filetype/helpers.py b/.venv/lib/python3.12/site-packages/filetype/helpers.py
new file mode 100644
index 00000000..afe4e684
--- /dev/null
+++ b/.venv/lib/python3.12/site-packages/filetype/helpers.py
@@ -0,0 +1,140 @@
+# -*- coding: utf-8 -*-
+
+from __future__ import absolute_import
+from .types import TYPES
+from .match import (
+    image_match, font_match, document_match,
+    video_match, audio_match, archive_match
+)
+
+
+def is_extension_supported(ext):
+    """
+    Checks if the given extension string is
+    one of the supported by the file matchers.
+
+    Args:
+        ext (str): file extension string. E.g: jpg, png, mp4, mp3
+
+    Returns:
+        True if the file extension is supported.
+        Otherwise False.
+    """
+    for kind in TYPES:
+        if kind.extension == ext:
+            return True
+    return False
+
+
+def is_mime_supported(mime):
+    """
+    Checks if the given MIME type string is
+    one of the supported by the file matchers.
+
+    Args:
+        mime (str): MIME string. E.g: image/jpeg, video/mpeg
+
+    Returns:
+        True if the MIME type is supported.
+        Otherwise False.
+    """
+    for kind in TYPES:
+        if kind.mime == mime:
+            return True
+    return False
+
+
+def is_image(obj):
+    """
+    Checks if a given input is a supported type image.
+
+    Args:
+        obj: path to file, bytes or bytearray.
+
+    Returns:
+        True if obj is a valid image. Otherwise False.
+
+    Raises:
+        TypeError: if obj is not a supported type.
+    """
+    return image_match(obj) is not None
+
+
+def is_archive(obj):
+    """
+    Checks if a given input is a supported type archive.
+
+    Args:
+        obj: path to file, bytes or bytearray.
+
+    Returns:
+        True if obj is a valid archive. Otherwise False.
+
+    Raises:
+        TypeError: if obj is not a supported type.
+    """
+    return archive_match(obj) is not None
+
+
+def is_audio(obj):
+    """
+    Checks if a given input is a supported type audio.
+
+    Args:
+        obj: path to file, bytes or bytearray.
+
+    Returns:
+        True if obj is a valid audio. Otherwise False.
+
+    Raises:
+        TypeError: if obj is not a supported type.
+    """
+    return audio_match(obj) is not None
+
+
+def is_video(obj):
+    """
+    Checks if a given input is a supported type video.
+
+    Args:
+        obj: path to file, bytes or bytearray.
+
+    Returns:
+        True if obj is a valid video. Otherwise False.
+
+    Raises:
+        TypeError: if obj is not a supported type.
+    """
+    return video_match(obj) is not None
+
+
+def is_font(obj):
+    """
+    Checks if a given input is a supported type font.
+
+    Args:
+        obj: path to file, bytes or bytearray.
+
+    Returns:
+        True if obj is a valid font. Otherwise False.
+
+    Raises:
+        TypeError: if obj is not a supported type.
+    """
+    return font_match(obj) is not None
+
+
+def is_document(obj):
+    """
+    Checks if a given input is a supported type document.
+
+    Args:
+        obj: path to file, bytes or bytearray.
+
+    Returns:
+        True if obj is a valid document. Otherwise False.
+
+    Raises:
+        TypeError: if obj is not a supported type.
+    """
+    return document_match(obj) is not None