| |
| *encoding* is ``None`` for no encoding or the name of the program used to encode |
| (e.g. :program:`compress` or :program:`gzip`). The encoding is suitable for use |
| as a :mailheader:`Content-Encoding` header, *not* as a |
| :mailheader:`Content-Transfer-Encoding` header. The mappings are table driven. |
| Encoding suffixes are case sensitive; type suffixes are first tried case |
| sensitively, then case insensitively. |
| |
n | Optional *strict* is a flag specifying whether the list of known MIME types is |
n | Optional *strict* is a flag specifying whether the list of known MIME types |
| limited to only the official types `registered with IANA <http://www.isi.edu/in- |
| is limited to only the official types `registered with IANA |
| notes/iana/assignments/media-types>`_ are recognized. When *strict* is true |
| <http://www.iana.org/assignments/media-types/>`_ are recognized. |
| (the default), only the IANA types are supported; when *strict* is false, some |
| When *strict* is true (the default), only the IANA types are supported; when |
| additional non-standard but commonly used MIME types are also recognized. |
| *strict* is false, some additional non-standard but commonly used MIME types |
| are also recognized. |
| |
| |
| .. function:: guess_all_extensions(type[, strict]) |
| |
| Guess the extensions for a file based on its MIME type, given by *type*. The |
| return value is a list of strings giving all possible filename extensions, |
| including the leading dot (``'.'``). The extensions are not guaranteed to have |
| been associated with any particular data stream, but would be mapped to the MIME |
| |
| |
| .. function:: add_type(type, ext[, strict]) |
| |
| Add a mapping from the mimetype *type* to the extension *ext*. When the |
| extension is already known, the new type will replace the old one. When the type |
| is already known the extension will be added to the list of known extensions. |
| |
n | When *strict* is the mapping will added to the official MIME types, otherwise to |
n | When *strict* is True (the default), the mapping will added to the official MIME |
| the non-standard ones. |
| types, otherwise to the non-standard ones. |
| |
| |
| .. data:: inited |
| |
| Flag indicating whether or not the global data structures have been initialized. |
| This is set to true by :func:`init`. |
| |
| |
| |
| MimeTypes Objects |
| ----------------- |
| |
| :class:`MimeTypes` instances provide an interface which is very like that of the |
| :mod:`mimetypes` module. |
| |
| |
n | .. data:: suffix_map |
n | .. attribute:: MimeTypes.suffix_map |
| |
| Dictionary mapping suffixes to suffixes. This is used to allow recognition of |
| encoded files for which the encoding and the type are indicated by the same |
| extension. For example, the :file:`.tgz` extension is mapped to :file:`.tar.gz` |
| to allow the encoding and type to be recognized separately. This is initially a |
| copy of the global ``suffix_map`` defined in the module. |
| |
| |
n | .. data:: encodings_map |
n | .. attribute:: MimeTypes.encodings_map |
| |
| Dictionary mapping filename extensions to encoding types. This is initially a |
| copy of the global ``encodings_map`` defined in the module. |
| |
| |
n | .. data:: types_map |
n | .. attribute:: MimeTypes.types_map |
| |
| Dictionary mapping filename extensions to MIME types. This is initially a copy |
| of the global ``types_map`` defined in the module. |
| |
| |
n | .. data:: common_types |
n | .. attribute:: MimeTypes.common_types |
| |
| Dictionary mapping filename extensions to non-standard, but commonly found MIME |
| types. This is initially a copy of the global ``common_types`` defined in the |
| module. |
| |
| |
n | .. method:: XXX Class.guess_extension(type[, strict]) |
n | .. method:: MimeTypes.guess_extension(type[, strict]) |
| |
| Similar to the :func:`guess_extension` function, using the tables stored as part |
| of the object. |
| |
| |
n | .. method:: XXX Class.guess_type(url[, strict]) |
n | .. method:: MimeTypes.guess_type(url[, strict]) |
| |
| Similar to the :func:`guess_type` function, using the tables stored as part of |
| the object. |
| |
| |
n | .. method:: XXX Class.read(path) |
n | .. method:: MimeTypes.read(path) |
| |
| Load MIME information from a file named *path*. This uses :meth:`readfp` to |
| parse the file. |
| |
| |
t | .. method:: XXX Class.readfp(file) |
t | .. method:: MimeTypes.readfp(file) |
| |
| Load MIME type information from an open file. The file must have the format of |
| the standard :file:`mime.types` files. |
| |