[Python-checkins] cpython (merge 3.2 -> default): Merge #11605: don't use set/get_payload in feedparser; they do conversions.
r.david.murray
python-checkins at python.org
Wed Apr 6 14:16:43 CEST 2011
http://hg.python.org/cpython/rev/642c0d6799c5
changeset: 69172:642c0d6799c5
parent: 69168:dc728ac66c3c
parent: 69171:b807cf929e26
user: R David Murray <rdmurray at bitdance.com>
date: Wed Apr 06 08:16:13 2011 -0400
summary:
Merge #11605: don't use set/get_payload in feedparser; they do conversions.
files:
Lib/email/feedparser.py | 4 +-
Lib/test/test_email/test_email.py | 47 +++++++++++++++++++
Misc/NEWS | 3 +
3 files changed, 52 insertions(+), 2 deletions(-)
diff --git a/Lib/email/feedparser.py b/Lib/email/feedparser.py
--- a/Lib/email/feedparser.py
+++ b/Lib/email/feedparser.py
@@ -368,12 +368,12 @@
end = len(mo.group(0))
self._last.epilogue = epilogue[:-end]
else:
- payload = self._last.get_payload()
+ payload = self._last._payload
if isinstance(payload, str):
mo = NLCRE_eol.search(payload)
if mo:
payload = payload[:-len(mo.group(0))]
- self._last.set_payload(payload)
+ self._last._payload = payload
self._input.pop_eof_matcher()
self._pop_message()
# Set the multipart up for newline cleansing, which will
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
@@ -3143,6 +3143,53 @@
g = email.generator.BytesGenerator(s)
g.flatten(msg, linesep='\r\n')
self.assertEqual(s.getvalue(), text)
+
+ def test_8bit_multipart(self):
+ # Issue 11605
+ source = textwrap.dedent("""\
+ Date: Fri, 18 Mar 2011 17:15:43 +0100
+ To: foo at example.com
+ From: foodwatch-Newsletter <bar at example.com>
+ Subject: Aktuelles zu Japan, Klonfleisch und Smiley-System
+ Message-ID: <76a486bee62b0d200f33dc2ca08220ad at localhost.localdomain>
+ MIME-Version: 1.0
+ Content-Type: multipart/alternative;
+ boundary="b1_76a486bee62b0d200f33dc2ca08220ad"
+
+ --b1_76a486bee62b0d200f33dc2ca08220ad
+ Content-Type: text/plain; charset="utf-8"
+ Content-Transfer-Encoding: 8bit
+
+ Guten Tag, ,
+
+ mit großer Betroffenheit verfolgen auch wir im foodwatch-Team die
+ Nachrichten aus Japan.
+
+
+ --b1_76a486bee62b0d200f33dc2ca08220ad
+ Content-Type: text/html; charset="utf-8"
+ Content-Transfer-Encoding: 8bit
+
+ <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
+ "http://www.w3.org/TR/html4/loose.dtd">
+ <html lang="de">
+ <head>
+ <title>foodwatch - Newsletter</title>
+ </head>
+ <body>
+ <p>mit großer Betroffenheit verfolgen auch wir im foodwatch-Team
+ die Nachrichten aus Japan.</p>
+ </body>
+ </html>
+ --b1_76a486bee62b0d200f33dc2ca08220ad--
+
+ """).encode('utf-8')
+ msg = email.message_from_bytes(source)
+ s = BytesIO()
+ g = email.generator.BytesGenerator(s)
+ g.flatten(msg)
+ self.assertEqual(s.getvalue(), source)
+
maxDiff = None
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -94,6 +94,9 @@
Library
-------
+- Issue #11605: email.parser.BytesFeedParser was incorrectly converting multipart
+ subpararts with an 8bit CTE into unicode instead of preserving the bytes.
+
- Issue #10963: Ensure that subprocess.communicate() never raises EPIPE.
- Issue #10791: Implement missing method GzipFile.read1(), allowing GzipFile
--
Repository URL: http://hg.python.org/cpython
More information about the Python-checkins
mailing list