Mercurial > repos > rliterman > csp2
comparison CSP2/CSP2_env/env-d9b9114564458d9d-741b3de822f2aaca6c6caa4325c4afce/lib/python3.8/email/mime/text.py @ 68:5028fdace37b
planemo upload commit 2e9511a184a1ca667c7be0c6321a36dc4e3d116d
author | jpayne |
---|---|
date | Tue, 18 Mar 2025 16:23:26 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
67:0e9998148a16 | 68:5028fdace37b |
---|---|
1 # Copyright (C) 2001-2006 Python Software Foundation | |
2 # Author: Barry Warsaw | |
3 # Contact: email-sig@python.org | |
4 | |
5 """Class representing text/* type MIME documents.""" | |
6 | |
7 __all__ = ['MIMEText'] | |
8 | |
9 from email.charset import Charset | |
10 from email.mime.nonmultipart import MIMENonMultipart | |
11 | |
12 | |
13 | |
14 class MIMEText(MIMENonMultipart): | |
15 """Class for generating text/* type MIME documents.""" | |
16 | |
17 def __init__(self, _text, _subtype='plain', _charset=None, *, policy=None): | |
18 """Create a text/* type MIME document. | |
19 | |
20 _text is the string for this message object. | |
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". Note that as a side-effect, the | |
26 Content-Transfer-Encoding header will also be set. | |
27 """ | |
28 | |
29 # If no _charset was specified, check to see if there are non-ascii | |
30 # characters present. If not, use 'us-ascii', otherwise use utf-8. | |
31 # XXX: This can be removed once #7304 is fixed. | |
32 if _charset is None: | |
33 try: | |
34 _text.encode('us-ascii') | |
35 _charset = 'us-ascii' | |
36 except UnicodeEncodeError: | |
37 _charset = 'utf-8' | |
38 | |
39 MIMENonMultipart.__init__(self, 'text', _subtype, policy=policy, | |
40 **{'charset': str(_charset)}) | |
41 | |
42 self.set_payload(_text, _charset) |