[Python-checkins] cpython (merge 3.4 -> default): Merge: #21079: is_attachment now looks only at the value, ignoring parameters.

r.david.murray python-checkins at python.org
Sat Sep 20 23:50:01 CEST 2014


https://hg.python.org/cpython/rev/54392c4a8880
changeset:   92493:54392c4a8880
parent:      92491:9e5389c92577
parent:      92492:0044ed0af96f
user:        R David Murray <rdmurray at bitdance.com>
date:        Sat Sep 20 17:49:48 2014 -0400
summary:
  Merge: #21079: is_attachment now looks only at the value, ignoring parameters.

files:
  Lib/email/message.py                |  4 +---
  Lib/test/test_email/test_message.py |  3 ++-
  Misc/NEWS                           |  3 +++
  3 files changed, 6 insertions(+), 4 deletions(-)


diff --git a/Lib/email/message.py b/Lib/email/message.py
--- a/Lib/email/message.py
+++ b/Lib/email/message.py
@@ -941,9 +941,7 @@
     @property
     def is_attachment(self):
         c_d = self.get('content-disposition')
-        if c_d is None:
-            return False
-        return c_d.lower() == 'attachment'
+        return False if c_d is None else c_d.content_disposition == 'attachment'
 
     def _find_body(self, part, preferencelist):
         if part.is_attachment:
diff --git a/Lib/test/test_email/test_message.py b/Lib/test/test_email/test_message.py
--- a/Lib/test/test_email/test_message.py
+++ b/Lib/test/test_email/test_message.py
@@ -729,7 +729,8 @@
         self.assertTrue(m.is_attachment)
         m.replace_header('Content-Disposition', 'AtTachMent')
         self.assertTrue(m.is_attachment)
-
+        m.set_param('filename', 'abc.png', 'Content-Disposition')
+        self.assertTrue(m.is_attachment)
 
 
 class TestEmailMessage(TestEmailMessageBase, TestEmailBase):
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -137,6 +137,9 @@
 Library
 -------
 
+- Issue #21079: Fix email.message.EmailMessage.is_attachment to return the
+  correct result when the header has parameters as well as a value.
+
 - Issue #22247: Add NNTPError to nntplib.__all__.
 
 - Issue #22366: urllib.request.urlopen will accept a context object

-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list