source: trunk/essentials/dev-lang/python/Lib/MimeWriter.py@ 3226

Last change on this file since 3226 was 3225, checked in by bird, 19 years ago

Python 2.5

File size: 6.2 KB
Line 
1"""Generic MIME writer.
2
3This module defines the class MimeWriter. The MimeWriter class implements
4a basic formatter for creating MIME multi-part files. It doesn't seek around
5the output file nor does it use large amounts of buffer space. You must write
6the parts out in the order that they should occur in the final file.
7MimeWriter does buffer the headers you add, allowing you to rearrange their
8order.
9
10"""
11
12
13import mimetools
14
15__all__ = ["MimeWriter"]
16
17class MimeWriter:
18
19 """Generic MIME writer.
20
21 Methods:
22
23 __init__()
24 addheader()
25 flushheaders()
26 startbody()
27 startmultipartbody()
28 nextpart()
29 lastpart()
30
31 A MIME writer is much more primitive than a MIME parser. It
32 doesn't seek around on the output file, and it doesn't use large
33 amounts of buffer space, so you have to write the parts in the
34 order they should occur on the output file. It does buffer the
35 headers you add, allowing you to rearrange their order.
36
37 General usage is:
38
39 f = <open the output file>
40 w = MimeWriter(f)
41 ...call w.addheader(key, value) 0 or more times...
42
43 followed by either:
44
45 f = w.startbody(content_type)
46 ...call f.write(data) for body data...
47
48 or:
49
50 w.startmultipartbody(subtype)
51 for each part:
52 subwriter = w.nextpart()
53 ...use the subwriter's methods to create the subpart...
54 w.lastpart()