mimetypes

Guess the MIME type of a file.

This module defines two useful functions:

guess_type(url, strict=1) – guess the MIME type and encoding of a URL.

guess_extension(type, strict=1) – guess the extension for a given MIME type.

It also contains the following, for tuning the behavior:

Data:

knownfiles – list of files to parse inited – flag set when init() has been called suffix_map – dictionary mapping suffixes to suffixes encodings_map – dictionary mapping suffixes to encodings types_map – dictionary mapping suffixes to types

Functions:

init([files]) – parse a list of files, default knownfiles (on Windows, the
default values are taken from the registry)

read_mime_types(file) – parse one file, return a dictionary or None

Functions

add_type(type, ext[, strict]) Add a mapping between a type and an extension.
guess_all_extensions(type[, strict]) Guess the extensions for a file based on its MIME type.
guess_extension(type[, strict]) Guess the extension for a file based on its MIME type.
guess_type(url[, strict]) Guess the type of a file based on its URL.
init([files])
read_mime_types(file)

Classes

MimeTypes([filenames, strict]) MIME-types datastore.