Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7c4093c

Browse files
committed
Merge: #21091: make is_attachment a method.
2 parents 1de0ac0 + 8a97896 commit 7c4093c

4 files changed

Lines changed: 17 additions & 10 deletions

File tree

Doc/library/email.contentmanager.rst

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,15 @@ this module.
7070
the following methods:
7171

7272

73-
.. attribute:: is_attachment
73+
.. method:: is_attachment
7474

75-
Set to ``True`` if there is a :mailheader:`Content-Disposition` header
75+
Return ``True`` if there is a :mailheader:`Content-Disposition` header
7676
and its (case insensitive) value is ``attachment``, ``False`` otherwise.
7777

78+
.. versionchanged:: 3.4.2
79+
is_attachment is now a method instead of a property, for consistency
80+
with :meth:`~email.message.Message.is_multipart`.
81+
7882

7983
.. method:: get_body(preferencelist=('related', 'html', 'plain'))
8084

Lib/email/message.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import re
1010
import uu
1111
import quopri
12+
import warnings
1213
from io import BytesIO, StringIO
1314

1415
# Intrapackage imports
@@ -938,13 +939,12 @@ def __init__(self, policy=None):
938939
policy = default
939940
Message.__init__(self, policy)
940941

941-
@property
942942
def is_attachment(self):
943943
c_d = self.get('content-disposition')
944944
return False if c_d is None else c_d.content_disposition == 'attachment'
945945

946946
def _find_body(self, part, preferencelist):
947-
if part.is_attachment:
947+
if part.is_attachment():
948948
return
949949
maintype, subtype = part.get_content_type().split('/')
950950
if maintype == 'text':
@@ -1037,7 +1037,7 @@ def iter_attachments(self):
10371037
for part in parts:
10381038
maintype, subtype = part.get_content_type().split('/')
10391039
if ((maintype, subtype) in self._body_types and
1040-
not part.is_attachment and subtype not in seen):
1040+
not part.is_attachment() and subtype not in seen):
10411041
seen.append(subtype)
10421042
continue
10431043
yield part

Lib/test/test_email/test_message.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -722,15 +722,15 @@ def message_as_clear_content(self, body_parts, attachments, parts, msg):
722722

723723
def test_is_attachment(self):
724724
m = self._make_message()
725-
self.assertFalse(m.is_attachment)
725+
self.assertFalse(m.is_attachment())
726726
m['Content-Disposition'] = 'inline'
727-
self.assertFalse(m.is_attachment)
727+
self.assertFalse(m.is_attachment())
728728
m.replace_header('Content-Disposition', 'attachment')
729-
self.assertTrue(m.is_attachment)
729+
self.assertTrue(m.is_attachment())
730730
m.replace_header('Content-Disposition', 'AtTachMent')
731-
self.assertTrue(m.is_attachment)
731+
self.assertTrue(m.is_attachment())
732732
m.set_param('filename', 'abc.png', 'Content-Disposition')
733-
self.assertTrue(m.is_attachment)
733+
self.assertTrue(m.is_attachment())
734734

735735

736736
class TestEmailMessage(TestEmailMessageBase, TestEmailBase):

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,9 @@ Core and Builtins
137137
Library
138138
-------
139139

140+
- Issue #21091: Fix API bug: email.message.EmailMessage.is_attachment is now
141+
a method.
142+
140143
- Issue #21079: Fix email.message.EmailMessage.is_attachment to return the
141144
correct result when the header has parameters as well as a value.
142145

0 commit comments

Comments
 (0)