mirror of
https://github.com/python/cpython.git
synced 2025-10-09 16:34:44 +00:00
#11019: Make BytesGenerator handle Message with None body.
Bug discovery and initial patch by Victor Stinner.
This commit is contained in:
parent
a63a312a3f
commit
7372a07fd0
3 changed files with 12 additions and 0 deletions
|
@ -377,6 +377,8 @@ class BytesGenerator(Generator):
|
||||||
def _handle_text(self, msg):
|
def _handle_text(self, msg):
|
||||||
# If the string has surrogates the original source was bytes, so
|
# If the string has surrogates the original source was bytes, so
|
||||||
# just write it back out.
|
# just write it back out.
|
||||||
|
if msg._payload is None:
|
||||||
|
return
|
||||||
if _has_surrogates(msg._payload):
|
if _has_surrogates(msg._payload):
|
||||||
self.write(msg._payload)
|
self.write(msg._payload)
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -2989,6 +2989,13 @@ class Test8BitBytesHandling(unittest.TestCase):
|
||||||
email.generator.BytesGenerator(out).flatten(msg)
|
email.generator.BytesGenerator(out).flatten(msg)
|
||||||
self.assertEqual(out.getvalue(), self.non_latin_bin_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("""\
|
non_latin_bin_msg_as7bit_wrapped = textwrap.dedent("""\
|
||||||
From: foo@bar.com
|
From: foo@bar.com
|
||||||
To: =?unknown-8bit?q?b=C3=A1z?=
|
To: =?unknown-8bit?q?b=C3=A1z?=
|
||||||
|
|
|
@ -16,6 +16,9 @@ Core and Builtins
|
||||||
Library
|
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
|
- Issue #11014: Make 'filter' argument in tarfile.Tarfile.add() into a
|
||||||
keyword-only argument. The preceding positional argument was deprecated,
|
keyword-only argument. The preceding positional argument was deprecated,
|
||||||
so it made no sense to add filter as a positional argument.
|
so it made no sense to add filter as a positional argument.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue