ยปCore Development>Code coverage>Lib/email/mime/text.py

Python code coverage for Lib/email/mime/text.py

#countcontent
1n/a# Copyright (C) 2001-2006 Python Software Foundation
2n/a# Author: Barry Warsaw
3n/a# Contact: email-sig@python.org
4n/a
5n/a"""Class representing text/* type MIME documents."""
6n/a
7n/a__all__ = ['MIMEText']
8n/a
9n/afrom email.charset import Charset
10n/afrom email.mime.nonmultipart import MIMENonMultipart
11n/a
12n/a
13n/a
14n/aclass MIMEText(MIMENonMultipart):
15n/a """Class for generating text/* type MIME documents."""
16n/a
17n/a def __init__(self, _text, _subtype='plain', _charset=None, *, policy=None):
18n/a """Create a text/* type MIME document.
19n/a
20n/a _text is the string for this message object.
21n/a
22n/a _subtype is the MIME sub content type, defaulting to "plain".
23n/a
24n/a _charset is the character set parameter added to the Content-Type
25n/a header. This defaults to "us-ascii". Note that as a side-effect, the
26n/a Content-Transfer-Encoding header will also be set.
27n/a """
28n/a
29n/a # If no _charset was specified, check to see if there are non-ascii
30n/a # characters present. If not, use 'us-ascii', otherwise use utf-8.
31n/a # XXX: This can be removed once #7304 is fixed.
32n/a if _charset is None:
33n/a try:
34n/a _text.encode('us-ascii')
35n/a _charset = 'us-ascii'
36n/a except UnicodeEncodeError:
37n/a _charset = 'utf-8'
38n/a
39n/a MIMENonMultipart.__init__(self, 'text', _subtype, policy=policy,
40n/a **{'charset': str(_charset)})
41n/a
42n/a self.set_payload(_text, _charset)