Commit 2b2a9be9 authored by Berker Peksag's avatar Berker Peksag

Issue #27445: Don't pass str(_charset) to MIMEText.set_payload()

Patch by Claude Paroz.
parent 82733fac
...@@ -35,10 +35,8 @@ class MIMEText(MIMENonMultipart): ...@@ -35,10 +35,8 @@ class MIMEText(MIMENonMultipart):
_charset = 'us-ascii' _charset = 'us-ascii'
except UnicodeEncodeError: except UnicodeEncodeError:
_charset = 'utf-8' _charset = 'utf-8'
if isinstance(_charset, Charset):
_charset = str(_charset)
MIMENonMultipart.__init__(self, 'text', _subtype, MIMENonMultipart.__init__(self, 'text', _subtype,
**{'charset': _charset}) **{'charset': str(_charset)})
self.set_payload(_text, _charset) self.set_payload(_text, _charset)
...@@ -1652,9 +1652,12 @@ class TestMIMEText(unittest.TestCase): ...@@ -1652,9 +1652,12 @@ class TestMIMEText(unittest.TestCase):
eq(msg.get_charset().input_charset, 'us-ascii') eq(msg.get_charset().input_charset, 'us-ascii')
eq(msg['content-type'], 'text/plain; charset="us-ascii"') eq(msg['content-type'], 'text/plain; charset="us-ascii"')
# Also accept a Charset instance # 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.get_charset().input_charset, 'utf-8')
eq(msg['content-type'], 'text/plain; charset="utf-8"') eq(msg['content-type'], 'text/plain; charset="utf-8"')
eq(msg.get_payload(), 'hello there')
def test_7bit_input(self): def test_7bit_input(self):
eq = self.assertEqual eq = self.assertEqual
......
...@@ -60,6 +60,9 @@ Core and Builtins ...@@ -60,6 +60,9 @@ Core and Builtins
Library 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 - lib2to3.pgen3.driver.load_grammar() now creates a stable cache file
between runs given the same Grammar.txt input regardless of the hash between runs given the same Grammar.txt input regardless of the hash
randomization setting. randomization setting.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment