From: Berker Peksag Date: Thu, 8 Sep 2016 16:40:30 +0000 (+0300) Subject: Issue #27445: Don't pass str(_charset) to MIMEText.set_payload() X-Git-Tag: v3.6.0b1~285^2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=2b2a9be9135be0135649a2a869856dbe4cc543f1;p=thirdparty%2FPython%2Fcpython.git Issue #27445: Don't pass str(_charset) to MIMEText.set_payload() Patch by Claude Paroz. --- diff --git a/Lib/email/mime/text.py b/Lib/email/mime/text.py index 479928ec945d..da03086ee8a7 100644 --- a/Lib/email/mime/text.py +++ b/Lib/email/mime/text.py @@ -35,10 +35,8 @@ class MIMEText(MIMENonMultipart): _charset = 'us-ascii' except UnicodeEncodeError: _charset = 'utf-8' - if isinstance(_charset, Charset): - _charset = str(_charset) MIMENonMultipart.__init__(self, 'text', _subtype, - **{'charset': _charset}) + **{'charset': str(_charset)}) self.set_payload(_text, _charset) diff --git a/Lib/test/test_email/test_email.py b/Lib/test/test_email/test_email.py index 1e5366c2a4e6..1d50feb593fa 100644 --- a/Lib/test/test_email/test_email.py +++ b/Lib/test/test_email/test_email.py @@ -1652,9 +1652,12 @@ class TestMIMEText(unittest.TestCase): eq(msg.get_charset().input_charset, 'us-ascii') eq(msg['content-type'], 'text/plain; charset="us-ascii"') # Also accept a Charset instance - msg = MIMEText('hello there', _charset=Charset('utf-8')) + charset = Charset('utf-8') + charset.body_encoding = None + msg = MIMEText('hello there', _charset=charset) eq(msg.get_charset().input_charset, 'utf-8') eq(msg['content-type'], 'text/plain; charset="utf-8"') + eq(msg.get_payload(), 'hello there') def test_7bit_input(self): eq = self.assertEqual diff --git a/Misc/NEWS b/Misc/NEWS index 15818383c4f0..a18ceb674e87 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -60,6 +60,9 @@ Core and Builtins Library ------- +- Issue #27445: Don't pass str(_charset) to MIMEText.set_payload(). + Patch by Claude Paroz. + - lib2to3.pgen3.driver.load_grammar() now creates a stable cache file between runs given the same Grammar.txt input regardless of the hash randomization setting.