file.utils ========== .. py:module:: file.utils Attributes ---------- .. autoapisummary:: file.utils.EXCLUDED_IMAGE_TYPES file.utils.IMAGE_MIME_TYPES file.utils.IMAGE_MIME_TYPES_AND_SVG Functions --------- .. autoapisummary:: file.utils.content_type_from_fileobj file.utils.as_fileintent file.utils.get_supported_image_mime_types file.utils.get_svg_size file.utils.extension_for_content_type file.utils.get_image_size file.utils.digest file.utils.word_count file.utils.name_without_extension file.utils.current_dir Module Contents --------------- .. py:function:: content_type_from_fileobj(fileobj: _typeshed.SupportsRead[bytes]) -> str Gets the content type from a file obj. Depot has this as well, but it doesn't use python-magic. We use python-magic to be slower, but more accurate. .. py:function:: as_fileintent(content: bytes | IO[bytes], filename: str | None) -> depot.io.utils.FileIntent .. py:function:: get_supported_image_mime_types() -> set[str] Queries PIL for *all* locally supported mime types. Adapted from: https://github.com/python-pillow/Pillow/issues/1182#issuecomment-90572583 .. py:function:: get_svg_size(svg: IO[bytes]) -> tuple[str | None, str | None] .. py:function:: extension_for_content_type(content_type: str, filename: str | None = None) -> str Gets the extension for the given content type. Note that this is *meant for display only*. A file claiming to be a PDF might not be one, but this function would not let you know that. .. py:function:: get_image_size(image: PIL.Image.Image) -> tuple[str, str] .. py:function:: digest(fileobj: _typeshed.SupportsRead[bytes], type: str = 'sha256', chunksize: int = 4096) -> str .. py:function:: word_count(text: str) -> int The word-count of the given text. Goes through the string exactly once and has constant memory usage. Not super sophisticated though. .. py:function:: name_without_extension(name: str) -> str .. py:function:: current_dir(dir: _typeshed.StrOrBytesPath) -> collections.abc.Iterator[None] .. py:data:: EXCLUDED_IMAGE_TYPES .. py:data:: IMAGE_MIME_TYPES .. py:data:: IMAGE_MIME_TYPES_AND_SVG