summaryrefslogtreecommitdiffstats
path: root/Doc
diff options
context:
space:
mode:
authorBarry Warsaw <barry@python.org>2001-10-25 21:49:18 (GMT)
committerBarry Warsaw <barry@python.org>2001-10-25 21:49:18 (GMT)
commit107771a228ee73b4683242cb696e3024f93b74d5 (patch)
tree34e96a4adcd53b74dfda667434b31b784095961a /Doc
parent9cd0efcee9d7ee29cd87eb0d1072351fbb986e08 (diff)
downloadcpython-107771a228ee73b4683242cb696e3024f93b74d5.zip
cpython-107771a228ee73b4683242cb696e3024f93b74d5.tar.gz
cpython-107771a228ee73b4683242cb696e3024f93b74d5.tar.bz2
Applying proposed patch for bug #474583, optional support for
non-standard but common types. Including Martin's suggestion to add rejected non-standard types from patch #438790. Specifically, guess_type(), guess_extension(): Both the functions and the methods grow an optional "strict" flag, defaulting to true, which determines whether to recognize non-standard, but commonly found types or not. Also, I sorted, reformatted, and culled duplicates from the big types_map dictionary. Note that there are a few non-equivalent duplicates (e.g. .cdf and .xls) for which the first will just get thrown away. I didn't remove those though. Finally, use of the module as a script as grown the -l and -e options to toggle strictness and to do guess_extension(), respectively. Doc and unittest updates too.
Diffstat (limited to 'Doc')
-rw-r--r--Doc/lib/libmimetypes.tex55
1 files changed, 39 insertions, 16 deletions
diff --git a/Doc/lib/libmimetypes.tex b/Doc/lib/libmimetypes.tex
index 327b2ba..3747fe1 100644
--- a/Doc/lib/libmimetypes.tex
+++ b/Doc/lib/libmimetypes.tex
@@ -8,10 +8,10 @@
\indexii{MIME}{content type}
-The \module{mimetypes} converts between a filename or URL and the MIME
-type associated with the filename extension. Conversions are provided
-from filename to MIME type and from MIME type to filename extension;
-encodings are not supported for the later conversion.
+The \module{mimetypes} module converts between a filename or URL and
+the MIME type associated with the filename extension. Conversions are
+provided from filename to MIME type and from MIME type to filename
+extension; encodings are not supported for the latter conversion.
The module provides one class and a number of convenience functions.
The functions are the normal interface to this module, but some
@@ -23,22 +23,31 @@ module. If the module has not been initialized, they will call
sets up.
-\begin{funcdesc}{guess_type}{filename}
+\begin{funcdesc}{guess_type}{filename\optional{, strict}}
Guess the type of a file based on its filename or URL, given by
\var{filename}. The return value is a tuple \code{(\var{type},
\var{encoding})} where \var{type} is \code{None} if the type can't be
-guessed (no or unknown suffix) or a string of the form
+guessed (missing or unknown suffix) or a string of the form
\code{'\var{type}/\var{subtype}'}, usable for a MIME
-\mailheader{content-type} header\indexii{MIME}{headers}; and encoding
-is \code{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, \emph{not}
-as a \mailheader{Content-Transfer-Encoding} header. The mappings are
-table driven. Encoding suffixes are case sensitive; type suffixes are
-first tried case sensitive, then case insensitive.
+\mailheader{content-type} header\indexii{MIME}{headers}.
+
+\var{encoding} is \code{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, \emph{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.
+
+Optional \var{strict} is a flag specifying whether the list of known
+MIME types is limited to only the official types \ulink{registered
+with IANA}{http://www.isi.edu/in-notes/iana/assignments/media-types}
+are recognized. When \var{strict} is true (the default), only the
+IANA types are supported; when \var{strict} is false, some additional
+non-standard but commonly used MIME types are also recognized.
\end{funcdesc}
-\begin{funcdesc}{guess_extension}{type}
+\begin{funcdesc}{guess_extension}{type\optional{, strict}}
Guess the extension for a file based on its MIME type, given by
\var{type}.
The return value is a string giving a filename extension, including the
@@ -46,6 +55,9 @@ leading dot (\character{.}). The extension is not guaranteed to have been
associated with any particular data stream, but would be mapped to the
MIME type \var{type} by \function{guess_type()}. If no extension can
be guessed for \var{type}, \code{None} is returned.
+
+Optional \var{strict} has the same meaning as with the
+\function{guess_type()} function.
\end{funcdesc}
@@ -98,6 +110,11 @@ Dictionary mapping filename extensions to encoding types.
Dictionary mapping filename extensions to MIME types.
\end{datadesc}
+\begin{datadesc}{common_types}
+Dictionary mapping filename extensions to non-standard, but commonly
+found MIME types.
+\end{datadesc}
+
The \class{MimeTypes} class may be useful for applications which may
want more than one MIME-type database:
@@ -144,12 +161,18 @@ that of the \refmodule{mimetypes} module.
module.
\end{datadesc}
-\begin{methoddesc}{guess_extension}{type}
+\begin{datadesc}{common_types}
+ Dictionary mapping filename extensions to non-standard, but commonly
+ found MIME types. This is initially a copy of the global
+ \code{common_types} defined in the module.
+\end{datadesc}
+
+\begin{methoddesc}{guess_extension}{type\optional{, strict}}
Similar to the \function{guess_extension()} function, using the
tables stored as part of the object.
\end{methoddesc}
-\begin{methoddesc}{guess_type}{url}
+\begin{methoddesc}{guess_type}{url\optional{, strict}}
Similar to the \function{guess_type()} function, using the tables
stored as part of the object.
\end{methoddesc}