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