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