changeset: 92495:f7aff40609e7 parent: 92493:54392c4a8880 parent: 92494:a3df1c24d586 user: R David Murray date: Sat Sep 20 18:16:39 2014 -0400 files: Lib/email/message.py Lib/test/test_email/test_message.py Misc/NEWS description: Merge: #21091: make is_attachment a method. diff -r 54392c4a8880 -r f7aff40609e7 Doc/library/email.contentmanager.rst --- a/Doc/library/email.contentmanager.rst Sat Sep 20 17:49:48 2014 -0400 +++ b/Doc/library/email.contentmanager.rst Sat Sep 20 18:16:39 2014 -0400 @@ -70,11 +70,15 @@ the following methods: - .. attribute:: is_attachment + .. method:: is_attachment - Set to ``True`` if there is a :mailheader:`Content-Disposition` header + Return ``True`` if there is a :mailheader:`Content-Disposition` header and its (case insensitive) value is ``attachment``, ``False`` otherwise. + .. versionchanged:: 3.4.2 + is_attachment is now a method instead of a property, for consistency + with :meth:`~email.message.Message.is_multipart`. + .. method:: get_body(preferencelist=('related', 'html', 'plain')) diff -r 54392c4a8880 -r f7aff40609e7 Lib/email/message.py --- a/Lib/email/message.py Sat Sep 20 17:49:48 2014 -0400 +++ b/Lib/email/message.py Sat Sep 20 18:16:39 2014 -0400 @@ -9,6 +9,7 @@ import re import uu import quopri +import warnings from io import BytesIO, StringIO # Intrapackage imports @@ -938,13 +939,12 @@ policy = default Message.__init__(self, policy) - @property def is_attachment(self): c_d = self.get('content-disposition') return False if c_d is None else c_d.content_disposition == 'attachment' def _find_body(self, part, preferencelist): - if part.is_attachment: + if part.is_attachment(): return maintype, subtype = part.get_content_type().split('/') if maintype == 'text': @@ -1037,7 +1037,7 @@ for part in parts: maintype, subtype = part.get_content_type().split('/') if ((maintype, subtype) in self._body_types and - not part.is_attachment and subtype not in seen): + not part.is_attachment() and subtype not in seen): seen.append(subtype) continue yield part diff -r 54392c4a8880 -r f7aff40609e7 Lib/test/test_email/test_message.py --- a/Lib/test/test_email/test_message.py Sat Sep 20 17:49:48 2014 -0400 +++ b/Lib/test/test_email/test_message.py Sat Sep 20 18:16:39 2014 -0400 @@ -722,15 +722,15 @@ def test_is_attachment(self): m = self._make_message() - self.assertFalse(m.is_attachment) + self.assertFalse(m.is_attachment()) m['Content-Disposition'] = 'inline' - self.assertFalse(m.is_attachment) + self.assertFalse(m.is_attachment()) m.replace_header('Content-Disposition', 'attachment') - self.assertTrue(m.is_attachment) + self.assertTrue(m.is_attachment()) m.replace_header('Content-Disposition', 'AtTachMent') - self.assertTrue(m.is_attachment) + self.assertTrue(m.is_attachment()) m.set_param('filename', 'abc.png', 'Content-Disposition') - self.assertTrue(m.is_attachment) + self.assertTrue(m.is_attachment()) class TestEmailMessage(TestEmailMessageBase, TestEmailBase): diff -r 54392c4a8880 -r f7aff40609e7 Misc/NEWS --- a/Misc/NEWS Sat Sep 20 17:49:48 2014 -0400 +++ b/Misc/NEWS Sat Sep 20 18:16:39 2014 -0400 @@ -137,6 +137,9 @@ Library ------- +- Issue #21091: Fix API bug: email.message.EmailMessage.is_attachment is now + a method. + - Issue #21079: Fix email.message.EmailMessage.is_attachment to return the correct result when the header has parameters as well as a value.