PyDocs

Internet Data Handling

mimetypes

Guess the MIME type of a file.

This module defines two useful functions:

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

guess_extension(type, strict=True) -- 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
Symbols in mimetypes

a

add_type
Add a mapping between a type and an extension.

c

common_types
Dictionary mapping filename extensions to non-standard, but commonly found MIME types.

e

encodings_map
Dictionary mapping filename extensions to encoding types.

g

guess_all_extensions
Guess the extensions for a file based on its MIME type.
guess_extension
Guess the extension for a file based on its MIME type.
guess_file_type
Guess the type of a file based on its path.
guess_type
Guess the type of a file based on its URL.

i

init
Initialize the internal data structures.
inited
Flag indicating whether or not the global data structures have been initialized.

k

knownfiles
List of type map file names commonly installed.

m

MimeTypes
MIME-types datastore.

r

read_mime_types
Load the type map given in the file named by file, if it exists.

s

suffix_map
Dictionary mapping suffixes to suffixes.

t

types_map
Dictionary mapping filename extensions to MIME types.