summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorR. David Murray <rdmurray@bitdance.com>2011-01-26 21:21:32 +0000
committerR. David Murray <rdmurray@bitdance.com>2011-01-26 21:21:32 +0000
commit7372a07fd0eb8e32fe9d03ee5a56ecc14788dfb0 (patch)
tree73992b4a0b679dcc803f4136056c60980fe3dd91
parenta63a312a3f5a4f3b76617831e56ac9d295929fa0 (diff)
downloadcpython-git-7372a07fd0eb8e32fe9d03ee5a56ecc14788dfb0.tar.gz
#11019: Make BytesGenerator handle Message with None body.
Bug discovery and initial patch by Victor Stinner.
-rw-r--r--Lib/email/generator.py2
-rw-r--r--Lib/email/test/test_email.py7
-rw-r--r--Misc/NEWS3
3 files changed, 12 insertions, 0 deletions
diff --git a/Lib/email/generator.py b/Lib/email/generator.py
index 9d33f1cb87..531fa9a7a4 100644
--- a/Lib/email/generator.py
+++ b/Lib/email/generator.py
@@ -377,6 +377,8 @@ class BytesGenerator(Generator):
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:
diff --git a/Lib/email/test/test_email.py b/Lib/email/test/test_email.py
index e4083ad63a..16772b1ee5 100644
--- a/Lib/email/test/test_email.py
+++ b/Lib/email/test/test_email.py
@@ -2989,6 +2989,13 @@ class Test8BitBytesHandling(unittest.TestCase):
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@bar.com
To: =?unknown-8bit?q?b=C3=A1z?=
diff --git a/Misc/NEWS b/Misc/NEWS
index f2e37b52a5..28803f8c10 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -16,6 +16,9 @@ Core and Builtins
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.