home *** CD-ROM | disk | FTP | other *** search
/ Freelog 33 / Freelog033.iso / Progr / Python-2.2.1.exe / MIMETEXT.PY < prev    next >
Encoding:
Python Source  |  2001-10-04  |  1.6 KB  |  42 lines

  1. # Copyright (C) 2001 Python Software Foundation
  2. # Author: barry@zope.com (Barry Warsaw)
  3.  
  4. """Class representing text/* type MIME documents.
  5. """
  6.  
  7. import MIMEBase
  8. from Encoders import encode_7or8bit
  9.  
  10.  
  11.  
  12. class MIMEText(MIMEBase.MIMEBase):
  13.     """Class for generating text/* type MIME documents."""
  14.  
  15.     def __init__(self, _text, _subtype='plain', _charset='us-ascii',
  16.                  _encoder=encode_7or8bit):
  17.         """Create a text/* type MIME document.
  18.  
  19.         _text is the string for this message object.  If the text does not end
  20.         in a newline, one is added.
  21.  
  22.         _subtype is the MIME sub content type, defaulting to "plain".
  23.  
  24.         _charset is the character set parameter added to the Content-Type:
  25.         header.  This defaults to "us-ascii".
  26.  
  27.         _encoder is a function which will perform the actual encoding for
  28.         transport of the text data.  It takes one argument, which is this
  29.         Text instance.  It should use get_payload() and set_payload() to
  30.         change the payload to the encoded form.  It should also add any
  31.         Content-Transfer-Encoding: or other headers to the message as
  32.         necessary.  The default encoding doesn't actually modify the payload,
  33.         but it does set Content-Transfer-Encoding: to either `7bit' or `8bit'
  34.         as appropriate.
  35.         """
  36.         MIMEBase.MIMEBase.__init__(self, 'text', _subtype,
  37.                                    **{'charset': _charset})
  38.         if _text and _text[-1] <> '\n':
  39.             _text += '\n'
  40.         self.set_payload(_text)
  41.         _encoder(self)
  42.