[Python-checkins] cpython (3.5): Issue #27445: Don't pass str(_charset) to MIMEText.set_payload()

berker.peksag python-checkins at python.org
Thu Sep 8 12:42:05 EDT 2016


https://hg.python.org/cpython/rev/4f6fef83cd0c
changeset: 103312:4f6fef83cd0c
branch: 3.5
parent: 103302:08f446bf45a7
user: Berker Peksag <berker.peksag at gmail.com>
date: Thu Sep 08 19:40:30 2016 +0300
summary:
 Issue #27445: Don't pass str(_charset) to MIMEText.set_payload()
Patch by Claude Paroz.
files:
 Lib/email/mime/text.py | 4 +---
 Lib/test/test_email/test_email.py | 5 ++++-
 Misc/NEWS | 3 +++
 3 files changed, 8 insertions(+), 4 deletions(-)
diff --git a/Lib/email/mime/text.py b/Lib/email/mime/text.py
--- a/Lib/email/mime/text.py
+++ b/Lib/email/mime/text.py
@@ -35,10 +35,8 @@
 _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
--- a/Lib/test/test_email/test_email.py
+++ b/Lib/test/test_email/test_email.py
@@ -1652,9 +1652,12 @@
 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
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -60,6 +60,9 @@
 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.
-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /