From 2b1b195d396ee92260425b17ee5d17b7f4525485 Mon Sep 17 00:00:00 2001 From: Facundo Batista Date: Sat, 19 Jan 2008 12:32:27 +0000 Subject: Fix issue #1822: MIMEMultipart.is_multipart() behaves correctly for a just-created (and empty) instance. Added tests for this. Thanks Jonathan Share. --- Lib/email/mime/multipart.py | 6 ++++++ Lib/email/test/test_email.py | 3 +++ Misc/NEWS | 3 +++ 3 files changed, 12 insertions(+) diff --git a/Lib/email/mime/multipart.py b/Lib/email/mime/multipart.py index 5c8c9db..9661865 100644 --- a/Lib/email/mime/multipart.py +++ b/Lib/email/mime/multipart.py @@ -34,6 +34,12 @@ class MIMEMultipart(MIMEBase): keyword arguments (or passed into the _params argument). """ MIMEBase.__init__(self, 'multipart', _subtype, **_params) + + # Initialise _payload to an empty list as the Message superclass's + # implementation of is_multipart assumes that _payload is a list for + # multipart messages. + self._payload = [] + if _subparts: for p in _subparts: self.attach(p) diff --git a/Lib/email/test/test_email.py b/Lib/email/test/test_email.py index 5a86da8..3a68f02 100644 --- a/Lib/email/test/test_email.py +++ b/Lib/email/test/test_email.py @@ -1861,6 +1861,9 @@ message 2 eq(msg.get_payload(0), text1) eq(msg.get_payload(1), text2) + def test_default_multipart_constructor(self): + msg = MIMEMultipart() + self.assertTrue(msg.is_multipart()) # A general test of parser->model->generator idempotency. IOW, read a message diff --git a/Misc/NEWS b/Misc/NEWS index cc74e16..35d9634 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -367,6 +367,9 @@ Core and builtins Library ------- +- #1822: MIMEMultipart.is_multipart() behaves correctly for a just-created + (and empty) instance. Thanks Jonathan Share. + - #1861: Added an attribute to the sched module which returns an ordered list of upcoming events (displayed as named tuples). -- cgit v0.12