1 module(email
,mime
,text
)
2 # Copyright (C) 2001-2006 Python Software Foundation
4 # Contact: email-sig@python.org
6 """Class representing text/* type MIME documents."""
10 from email
.charset
import Charset
11 from email
.mime
.nonmultipart
import MIMENonMultipart
15 class MIMEText(MIMENonMultipart
):
16 """Class for generating text/* type MIME documents."""
18 def __init__(self
, _text
, _subtype
='plain', _charset
=None, *, policy
=None):
19 """Create a text/* type MIME document.
21 _text is the string for this message object.
23 _subtype is the MIME sub content type, defaulting to "plain".
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.
30 # If no _charset was specified, check to see if there are non-ascii
31 # characters present. If not, use 'us-ascii', otherwise use utf-8.
32 # XXX: This can be removed once #7304 is fixed.
35 _text
.encode('us-ascii')
37 except UnicodeEncodeError:
40 MIMENonMultipart
.__init
__(self
, 'text', _subtype
, policy
=policy
,
41 **{'charset': str(_charset
)})
43 self
.set_payload(_text
, _charset
)