summaryrefslogtreecommitdiff
path: root/Lib/email/mime
diff options
context:
space:
mode:
authorR David Murray <rdmurray@bitdance.com>2012-03-22 22:40:44 -0400
committerR David Murray <rdmurray@bitdance.com>2012-03-22 22:40:44 -0400
commit42243c4dcaee5fe6e680d1ea4b1b615dd0d18b10 (patch)
tree51752ab3326f8eff02fadeb46f8f604a92cc6447 /Lib/email/mime
parent8680bcc5db7c0edc09b09387c145932da34cd889 (diff)
downloadcpython-git-42243c4dcaee5fe6e680d1ea4b1b615dd0d18b10.tar.gz
#14380: Make actual default match docs, fix __init__ order.
Éric pointed out that given that the default was documented as None, someone would reasonably pass that to get the default behavior. In fixing the code to use None, I noticed that the change to _charset was being done after it had already been passed to MIMENonMultipart. The change to the test verifies that the order is now correct.
Diffstat (limited to 'Lib/email/mime')
-rw-r--r--Lib/email/mime/text.py16
1 files changed, 9 insertions, 7 deletions
diff --git a/Lib/email/mime/text.py b/Lib/email/mime/text.py
index 5a5e39bb38..80ff95010f 100644
--- a/Lib/email/mime/text.py
+++ b/Lib/email/mime/text.py
@@ -14,7 +14,7 @@ from email.mime.nonmultipart import MIMENonMultipart
class MIMEText(MIMENonMultipart):
"""Class for generating text/* type MIME documents."""
- def __init__(self, _text, _subtype='plain', _charset='us-ascii'):
+ def __init__(self, _text, _subtype='plain', _charset=None):
"""Create a text/* type MIME document.
_text is the string for this message object.
@@ -25,16 +25,18 @@ class MIMEText(MIMENonMultipart):
header. This defaults to "us-ascii". Note that as a side-effect, the
Content-Transfer-Encoding header will also be set.
"""
- MIMENonMultipart.__init__(self, 'text', _subtype,
- **{'charset': _charset})
- # If _charset was defualted, check to see see if there are non-ascii
- # characters present. Default to utf-8 if there are.
+ # If no _charset was specified, check to see see if there are non-ascii
+ # characters present. If not, use 'us-ascii', otherwise use utf-8.
# XXX: This can be removed once #7304 is fixed.
- if _charset =='us-ascii':
+ if _charset is None:
try:
- _text.encode(_charset)
+ _text.encode('us-ascii')
+ _charset = 'us-ascii'
except UnicodeEncodeError:
_charset = 'utf-8'
+ MIMENonMultipart.__init__(self, 'text', _subtype,
+ **{'charset': _charset})
+
self.set_payload(_text, _charset)