Module mimetypeplus.mimetypecheckers
mimetypecheckers
Type checker utilities for the MimeType module
Functions
def mime_string_from_data(buffer: Union[bytes, str], *, hint_path: Union[str, os.PathLike, ForwardRef(None)] = None, encoding: str = 'utf8', errors: str = 'strict') ‑> Optional[str]
-
mime_string_from_data Gets the mime type from the given data.
Arguments
buffer - Either bytes or a string. hint_path - A optional path to the data if located on the system. Used to make some typechecks more accurate. encoding - The presumed encoding of the data if it is a string. This does not have to be accurate in cases where the content is expected to be a binary format, and the content is already bytes. This is used to encode strings, or decode bytes into the oppsite form, allowing for more type checksers to be used. errors - See the encoding argument. Used in the same context, but indicates how to handle encoding/decoding errors. Values match the values used in the str.encode and bytes.decode errors argument.
Returns
String with a correct mimetype if possible, otherwise None.
def mime_string_from_path(path: Union[pathlib.Path, os.PathLike, str], strict: bool = False, *, no_local_checks: bool = False) ‑> Optional[str]
-
mime_string_from_path Gets the mime type from the given local path.
Arguments
path - The path to be checked. strict - Allow for non standard types to be included in some types of checking. no_local_checks - Skips checks that requires a path to be available on the local filesystem. Allows for URIs to be checked safely.
Returns
String with a correct mimetype if possible, otherwise None.
def mime_string_from_xml_content(content_snippet: str) ‑> Optional[str]
-
mime_string_from_xml_content Gets the mime type from the given text content of a xml file if possible. Usually usefull for correcting self reported content types of pages retrieved from the web; which may return a plain text mimetype even though the content may be a type of xml.
Arguments
content_snippet - The beginning snippet of the content as a string.
Returns
String with a correct mimetype if possible, otherwise None.