diff options
author | R David Murray <rdmurray@bitdance.com> | 2014-09-20 22:05:28 (GMT) |
---|---|---|
committer | R David Murray <rdmurray@bitdance.com> | 2014-09-20 22:05:28 (GMT) |
commit | 8a97896a765e4b1ef8753b4a410a8f3e981cb9b8 (patch) | |
tree | f21bd8d39436e5bb9b8d8937511fbcaab2ddcff6 /Lib/email/message.py | |
parent | 97dfad7856df5d9c681fa74d576a23247cc55a33 (diff) | |
download | cpython-8a97896a765e4b1ef8753b4a410a8f3e981cb9b8.zip cpython-8a97896a765e4b1ef8753b4a410a8f3e981cb9b8.tar.gz cpython-8a97896a765e4b1ef8753b4a410a8f3e981cb9b8.tar.bz2 |
#21091: make is_attachment a method.
Since EmailMessage is a provisional API we can fix API bugs in a
maintenance release, but I used a trick suggested by Serhiy to
maintain backward compatibility with 3.4.0/1.
Diffstat (limited to 'Lib/email/message.py')
-rw-r--r-- | Lib/email/message.py | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/Lib/email/message.py b/Lib/email/message.py index 124071d..a179f8e 100644 --- a/Lib/email/message.py +++ b/Lib/email/message.py @@ -9,6 +9,7 @@ __all__ = ['Message'] import re import uu import quopri +import warnings from io import BytesIO, StringIO # Intrapackage imports @@ -929,6 +930,17 @@ class Message: # I.e. def walk(self): ... from email.iterators import walk +# XXX Support for temporary deprecation hack for is_attachment property. +class _IsAttachment: + def __init__(self, value): + self.value = value + def __call__(self): + return self.value + def __bool__(self): + warnings.warn("is_attachment will be a method, not a property, in 3.5", + DeprecationWarning, + stacklevel=3) + return self.value class MIMEPart(Message): @@ -941,10 +953,12 @@ class MIMEPart(Message): @property def is_attachment(self): c_d = self.get('content-disposition') - return False if c_d is None else c_d.content_disposition == 'attachment' + result = False if c_d is None else c_d.content_disposition == 'attachment' + # XXX transitional hack to raise deprecation if not called. + return _IsAttachment(result) 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 +1051,7 @@ class MIMEPart(Message): 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 |