MCPcopy Index your code
hub / github.com/python/cpython / MIMEText

Class MIMEText

Lib/email/mime/text.py:12–40  ·  view source on GitHub ↗

Class for generating text/* type MIME documents.

Source from the content-addressed store, hash-verified

10
11
12class MIMEText(MIMENonMultipart):
13 """Class for generating text/* type MIME documents."""
14
15 def __init__(self, _text, _subtype='plain', _charset=None, *, policy=None):
16 """Create a text/* type MIME document.
17
18 _text is the string for this message object.
19
20 _subtype is the MIME sub content type, defaulting to "plain".
21
22 _charset is the character set parameter added to the Content-Type
23 header. This defaults to "us-ascii". Note that as a side-effect, the
24 Content-Transfer-Encoding header will also be set.
25 """
26
27 # If no _charset was specified, check to see if there are non-ascii
28 # characters present. If not, use 'us-ascii', otherwise use utf-8.
29 # XXX: This can be removed once #7304 is fixed.
30 if _charset is None:
31 try:
32 _text.encode('us-ascii')
33 _charset = 'us-ascii'
34 except UnicodeEncodeError:
35 _charset = 'utf-8'
36
37 MIMENonMultipart.__init__(self, 'text', _subtype, policy=policy,
38 charset=str(_charset))
39
40 self.set_payload(_text, _charset)

Callers 15

test_default_cteMethod · 0.90
test_encode7or8bitMethod · 0.90
test_qp_encode_latin1Method · 0.90
test_header_splitterMethod · 0.90
setUpMethod · 0.90
test_charsetMethod · 0.90
test_7bit_inputMethod · 0.90
test_utf8_inputMethod · 0.90

Calls

no outgoing calls

Tested by 15

test_default_cteMethod · 0.72
test_encode7or8bitMethod · 0.72
test_qp_encode_latin1Method · 0.72
test_header_splitterMethod · 0.72
setUpMethod · 0.72
test_charsetMethod · 0.72
test_7bit_inputMethod · 0.72
test_utf8_inputMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…