blob: 41a62bab664903a7ffe7c2fcd582429ec01aa325 [file] [log] [blame]
Guido van Rossum470be141995-03-17 16:07:09 +00001\section{Standard Module \sectcode{mimetools}}
Guido van Rossume47da0a1997-07-17 16:34:52 +00002\label{module-mimetools}
Guido van Rossuma12ef941995-02-27 17:53:25 +00003\stmodindex{mimetools}
Guido van Rossum86751151995-02-28 17:14:32 +00004
5\renewcommand{\indexsubitem}{(in module mimetools)}
6
Guido van Rossumcca8d2b1995-03-22 15:48:46 +00007This module defines a subclass of the class \code{rfc822.Message} and
8a number of utility functions that are useful for the manipulation for
9MIME style multipart or encoded message.
10
11It defines the following items:
12
13\begin{funcdesc}{Message}{fp}
14Return a new instance of the \code{mimetools.Message} class. This is
15a subclass of the \code{rfc822.Message} class, with some additional
16methods (see below).
17\end{funcdesc}
18
19\begin{funcdesc}{choose_boundary}{}
20Return a unique string that has a high likelihood of being usable as a
21part boundary. The string has the form
22\code{"\var{hostipaddr}.\var{uid}.\var{pid}.\var{timestamp}.\var{random}"}.
23\end{funcdesc}
24
25\begin{funcdesc}{decode}{input\, output\, encoding}
26Read data encoded using the allowed MIME \var{encoding} from open file
27object \var{input} and write the decoded data to open file object
28\var{output}. Valid values for \var{encoding} include
29\code{"base64"}, \code{"quoted-printable"} and \code{"uuencode"}.
30\end{funcdesc}
31
32\begin{funcdesc}{encode}{input\, output\, encoding}
33Read data from open file object \var{input} and write it encoded using
34the allowed MIME \var{encoding} to open file object \var{output}.
35Valid values for \var{encoding} are the same as for \code{decode()}.
36\end{funcdesc}
37
38\begin{funcdesc}{copyliteral}{input\, output}
39Read lines until EOF from open file \var{input} and write them to open
40file \var{output}.
41\end{funcdesc}
42
43\begin{funcdesc}{copybinary}{input\, output}
44Read blocks until EOF from open file \var{input} and write them to open
45file \var{output}. The block size is currently fixed at 8192.
46\end{funcdesc}
47
48
Guido van Rossumecde7811995-03-28 13:35:14 +000049\subsection{Additional Methods of Message objects}
Guido van Rossumcca8d2b1995-03-22 15:48:46 +000050\nodename{mimetools.Message Methods}
51
52The \code{mimetools.Message} class defines the following methods in
53addition to the \code{rfc822.Message} class:
54
55\renewcommand{\indexsubitem}{(mimetool.Message method)}
56
57\begin{funcdesc}{getplist}{}
58Return the parameter list of the \code{Content-type} header. This is
59a list if strings. For parameters of the form
60\samp{\var{key}=\var{value}}, \var{key} is converted to lower case but
61\var{value} is not. For example, if the message contains the header
62\samp{Content-type: text/html; spam=1; Spam=2; Spam} then
63\code{getplist()} will return the Python list \code{['spam=1',
64'spam=2', 'Spam']}.
65\end{funcdesc}
66
67\begin{funcdesc}{getparam}{name}
68Return the \var{value} of the first parameter (as returned by
69\code{getplist()} of the form \samp{\var{name}=\var{value}} for the
70given \var{name}. If \var{value} is surrounded by quotes of the form
71\var{<...>} or \var{"..."}, these are removed.
72\end{funcdesc}
73
74\begin{funcdesc}{getencoding}{}
75Return the encoding specified in the \samp{Content-transfer-encoding}
76message header. If no such header exists, return \code{"7bit"}. The
77encoding is converted to lower case.
78\end{funcdesc}
79
80\begin{funcdesc}{gettype}{}
Fred Drake4b3f0311996-12-13 22:04:31 +000081Return the message type (of the form \samp{\var{type}/\var{subtype}})
Guido van Rossumcca8d2b1995-03-22 15:48:46 +000082as specified in the \samp{Content-type} header. If no such header
83exists, return \code{"text/plain"}. The type is converted to lower
84case.
85\end{funcdesc}
86
87\begin{funcdesc}{getmaintype}{}
88Return the main type as specified in the \samp{Content-type} header.
89If no such header exists, return \code{"text"}. The main type is
90converted to lower case.
91\end{funcdesc}
92
93\begin{funcdesc}{getsubtype}{}
94Return the subtype as specified in the \samp{Content-type} header. If
95no such header exists, return \code{"plain"}. The subtype is
96converted to lower case.
97\end{funcdesc}