[Python-checkins] python/dist/src/Lib MimeWriter.py,1.7,1.7.24.1
rhettinger@users.sourceforge.net
rhettinger@users.sourceforge.net
2002年5月29日 16:05:49 -0700
Update of /cvsroot/python/python/dist/src/Lib
In directory usw-pr-cvs1:/tmp/cvs-serv30766
Modified Files:
Tag: release22-maint
MimeWriter.py
Log Message:
Backport change to 1.8 adding docstrings
Index: MimeWriter.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/MimeWriter.py,v
retrieving revision 1.7
retrieving revision 1.7.24.1
diff -C2 -d -r1.7 -r1.7.24.1
*** MimeWriter.py 9 Feb 2001 09:34:36 -0000 1.7
--- MimeWriter.py 29 May 2002 23:05:46 -0000 1.7.24.1
***************
*** 1,7 ****
"""Generic MIME writer.
! Classes:
!
! MimeWriter - the only thing here.
"""
--- 1,10 ----
"""Generic MIME writer.
! This module defines the class MimeWriter. The MimeWriter class implements
! a basic formatter for creating MIME multi-part files. It doesn't seek around
! the output file nor does it use large amounts of buffer space. You must write
! the parts out in the order that they should occur in the final file.
! MimeWriter does buffer the headers you add, allowing you to rearrange their
! order.
"""
***************
*** 87,90 ****
--- 90,101 ----
def addheader(self, key, value, prefix=0):
+ """Add a header line to the MIME message.
+
+ The key is the name of the header, where the value obviously provides
+ the value of the header. The optional argument prefix determines
+ where the header is inserted; 0 means append at the end, 1 means
+ insert at the start. The default is to append.
+
+ """
lines = value.split("\n")
while lines and not lines[-1]: del lines[-1]
***************
*** 100,107 ****
--- 111,134 ----
def flushheaders(self):
+ """Writes out and forgets all headers accumulated so far.
+
+ This is useful if you don't need a body part at all; for example,
+ for a subpart of type message/rfc822 that's (mis)used to store some
+ header-like information.
+
+ """
self._fp.writelines(self._headers)
self._headers = []
def startbody(self, ctype, plist=[], prefix=1):
+ """Returns a file-like object for writing the body of the message.
+
+ The content-type is set to the provided ctype, and the optional
+ parameter, plist, provides additional parameters for the
+ content-type declaration. The optional argument prefix determines
+ where the header is inserted; 0 means append at the end, 1 means
+ insert at the start. The default is to insert at the start.
+
+ """
for name, value in plist:
ctype = ctype + ';\n %s=\"%s\"' % (name, value)
***************
*** 112,115 ****
--- 139,154 ----
def startmultipartbody(self, subtype, boundary=None, plist=[], prefix=1):
+ """Returns a file-like object for writing the body of the message.
+
+ Additionally, this method initializes the multi-part code, where the
+ subtype parameter provides the multipart subtype, the boundary
+ parameter may provide a user-defined boundary specification, and the
+ plist parameter provides optional parameters for the subtype. The
+ optional argument, prefix, determines where the header is inserted;
+ 0 means append at the end, 1 means insert at the start. The default
+ is to insert at the start. Subparts should be created using the
+ nextpart() method.
+
+ """
self._boundary = boundary or mimetools.choose_boundary()
return self.startbody("multipart/" + subtype,
***************
*** 118,125 ****
--- 157,178 ----
def nextpart(self):
+ """Returns a new instance of MimeWriter which represents an
+ individual part in a multipart message.
+
+ This may be used to write the part as well as used for creating
+ recursively complex multipart messages. The message must first be
+ initialized with the startmultipartbody() method before using the
+ nextpart() method.
+
+ """
self._fp.write("\n--" + self._boundary + "\n")
return self.__class__(self._fp)
def lastpart(self):
+ """This is used to designate the last part of a multipart message.
+
+ It should always be used when writing multipart messages.
+
+ """
self._fp.write("\n--" + self._boundary + "--\n")