Updated for 2.1a3
[python/dscho.git] / Doc / lib / libmimewriter.tex
blobfbf24901be018f88a89bf099bb1af875f48dfabb
1 \section{\module{MimeWriter} ---
2 Generic MIME file writer}
4 \declaremodule{standard}{MimeWriter}
6 \modulesynopsis{Generic MIME file writer.}
7 \sectionauthor{Christopher G. Petrilli}{petrilli@amber.org}
9 This module defines the class \class{MimeWriter}. The
10 \class{MimeWriter} class implements a basic formatter for creating
11 MIME multi-part files. It doesn't seek around the output file nor
12 does it use large amounts of buffer space. You must write the parts
13 out in the order that they should occur in the final
14 file. \class{MimeWriter} does buffer the headers you add, allowing you
15 to rearrange their order.
17 \begin{classdesc}{MimeWriter}{fp}
18 Return a new instance of the \class{MimeWriter} class. The only
19 argument passed, \var{fp}, is a file object to be used for
20 writing. Note that a \class{StringIO} object could also be used.
21 \end{classdesc}
24 \subsection{MimeWriter Objects \label{MimeWriter-objects}}
27 \class{MimeWriter} instances have the following methods:
29 \begin{methoddesc}{addheader}{key, value\optional{, prefix}}
30 Add a header line to the MIME message. The \var{key} is the name of
31 the header, where the \var{value} obviously provides the value of the
32 header. The optional argument \var{prefix} determines where the header
33 is inserted; \samp{0} means append at the end, \samp{1} is insert at
34 the start. The default is to append.
35 \end{methoddesc}
37 \begin{methoddesc}{flushheaders}{}
38 Causes all headers accumulated so far to be written out (and
39 forgotten). This is useful if you don't need a body part at all,
40 e.g.\ for a subpart of type \mimetype{message/rfc822} that's (mis)used
41 to store some header-like information.
42 \end{methoddesc}
44 \begin{methoddesc}{startbody}{ctype\optional{, plist\optional{, prefix}}}
45 Returns a file-like object which can be used to write to the
46 body of the message. The content-type is set to the provided
47 \var{ctype}, and the optional parameter \var{plist} provides
48 additional parameters for the content-type declaration. \var{prefix}
49 functions as in \method{addheader()} except that the default is to
50 insert at the start.
51 \end{methoddesc}
53 \begin{methoddesc}{startmultipartbody}{subtype\optional{,
54 boundary\optional{, plist\optional{, prefix}}}}
55 Returns a file-like object which can be used to write to the
56 body of the message. Additionally, this method initializes the
57 multi-part code, where \var{subtype} provides the multipart subtype,
58 \var{boundary} may provide a user-defined boundary specification, and
59 \var{plist} provides optional parameters for the subtype.
60 \var{prefix} functions as in \method{startbody()}. Subparts should be
61 created using \method{nextpart()}.
62 \end{methoddesc}
64 \begin{methoddesc}{nextpart}{}
65 Returns a new instance of \class{MimeWriter} which represents an
66 individual part in a multipart message. This may be used to write the
67 part as well as used for creating recursively complex multipart
68 messages. The message must first be initialized with
69 \method{startmultipartbody()} before using \method{nextpart()}.
70 \end{methoddesc}
72 \begin{methoddesc}{lastpart}{}
73 This is used to designate the last part of a multipart message, and
74 should \emph{always} be used when writing multipart messages.
75 \end{methoddesc}