[Python-checkins] r88203 - in python/branches/py3k: Lib/email/generator.py Lib/email/test/test_email.py Misc/NEWS

r.david.murray python-checkins at python.org
Wed Jan 26 22:21:32 CET 2011


Author: r.david.murray
Date: Wed Jan 26 22:21:32 2011
New Revision: 88203
Log:
#11019: Make BytesGenerator handle Message with None body.
Bug discovery and initial patch by Victor Stinner.
Modified:
 python/branches/py3k/Lib/email/generator.py
 python/branches/py3k/Lib/email/test/test_email.py
 python/branches/py3k/Misc/NEWS
Modified: python/branches/py3k/Lib/email/generator.py
==============================================================================
--- python/branches/py3k/Lib/email/generator.py	(original)
+++ python/branches/py3k/Lib/email/generator.py	Wed Jan 26 22:21:32 2011
@@ -377,6 +377,8 @@
 def _handle_text(self, msg):
 # If the string has surrogates the original source was bytes, so
 # just write it back out.
+ if msg._payload is None:
+ return
 if _has_surrogates(msg._payload):
 self.write(msg._payload)
 else:
Modified: python/branches/py3k/Lib/email/test/test_email.py
==============================================================================
--- python/branches/py3k/Lib/email/test/test_email.py	(original)
+++ python/branches/py3k/Lib/email/test/test_email.py	Wed Jan 26 22:21:32 2011
@@ -2989,6 +2989,13 @@
 email.generator.BytesGenerator(out).flatten(msg)
 self.assertEqual(out.getvalue(), self.non_latin_bin_msg)
 
+ def test_bytes_generator_handles_None_body(self):
+ #Issue 11019
+ msg = email.message.Message()
+ out = BytesIO()
+ email.generator.BytesGenerator(out).flatten(msg)
+ self.assertEqual(out.getvalue(), b"\n")
+
 non_latin_bin_msg_as7bit_wrapped = textwrap.dedent("""\
 From: foo at bar.com
 To: =?unknown-8bit?q?b=C3=A1z?=
Modified: python/branches/py3k/Misc/NEWS
==============================================================================
--- python/branches/py3k/Misc/NEWS	(original)
+++ python/branches/py3k/Misc/NEWS	Wed Jan 26 22:21:32 2011
@@ -16,6 +16,9 @@
 Library
 -------
 
+- Issue #11019: Fixed BytesGenerator so that it correctly handles a Message
+ with a None body.
+
 - Issue #11014: Make 'filter' argument in tarfile.Tarfile.add() into a
 keyword-only argument. The preceding positional argument was deprecated,
 so it made no sense to add filter as a positional argument.


More information about the Python-checkins mailing list

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