home *** CD-ROM | disk | FTP | other *** search
/ Komputer for Alle 2004 #2 / K-CD-2-2004.ISO / OpenOffice Sv / f_0397 / python-core-2.2.2 / lib / email / MIMEText.py < prev    next >
Encoding:
Python Source  |  2003-07-18  |  1.9 KB  |  49 lines

  1. # Copyright (C) 2001,2002 Python Software Foundation
  2. # Author: barry@zope.com (Barry Warsaw)
  3.  
  4. """Class representing text/* type MIME documents.
  5. """
  6.  
  7. import warnings
  8. from email.MIMENonMultipart import MIMENonMultipart
  9. from email.Encoders import encode_7or8bit
  10.  
  11.  
  12.  
  13. class MIMEText(MIMENonMultipart):
  14.     """Class for generating text/* type MIME documents."""
  15.  
  16.     def __init__(self, _text, _subtype='plain', _charset='us-ascii',
  17.                  _encoder=None):
  18.         """Create a text/* type MIME document.
  19.  
  20.         _text is the string for this message object.  If the text does not end
  21.         in a newline, one is added.
  22.  
  23.         _subtype is the MIME sub content type, defaulting to "plain".
  24.  
  25.         _charset is the character set parameter added to the Content-Type
  26.         header.  This defaults to "us-ascii".  Note that as a side-effect, the
  27.         Content-Transfer-Encoding header will also be set.
  28.  
  29.         The use of the _encoder is deprecated.  The encoding of the payload,
  30.         and the setting of the character set parameter now happens implicitly
  31.         based on the _charset argument.  If _encoder is supplied, then a
  32.         DeprecationWarning is used, and the _encoder functionality may
  33.         override any header settings indicated by _charset.  This is probably
  34.         not what you want.
  35.         """
  36.         MIMENonMultipart.__init__(self, 'text', _subtype,
  37.                                   **{'charset': _charset})
  38.         if _text and not _text.endswith('\n'):
  39.             _text += '\n'
  40.         self.set_payload(_text, _charset)
  41.         if _encoder is not None:
  42.             warnings.warn('_encoder argument is obsolete.',
  43.                           DeprecationWarning, 2)
  44.             # Because set_payload() with a _charset will set its own
  45.             # Content-Transfer-Encoding header, we need to delete the
  46.             # existing one or will end up with two of them. :(
  47.             del self['content-transfer-encoding']
  48.             _encoder(self)
  49.