mirror of
https://github.com/python/cpython.git
synced 2025-11-17 09:30:10 +00:00
#11558: Better message if attach called on non-multipart.
Original patch by Varun Sharma.
This commit is contained in:
parent
733e50ad9e
commit
5dda12491e
4 changed files with 18 additions and 1 deletions
|
|
@ -203,7 +203,11 @@ class Message:
|
||||||
if self._payload is None:
|
if self._payload is None:
|
||||||
self._payload = [payload]
|
self._payload = [payload]
|
||||||
else:
|
else:
|
||||||
self._payload.append(payload)
|
try:
|
||||||
|
self._payload.append(payload)
|
||||||
|
except AttributeError:
|
||||||
|
raise TypeError("Attach is not valid on a message with a"
|
||||||
|
" non-multipart payload")
|
||||||
|
|
||||||
def get_payload(self, i=None, decode=False):
|
def get_payload(self, i=None, decode=False):
|
||||||
"""Return a reference to the payload.
|
"""Return a reference to the payload.
|
||||||
|
|
|
||||||
|
|
@ -124,6 +124,14 @@ class TestMessageAPI(TestEmailBase):
|
||||||
msg.set_payload([])
|
msg.set_payload([])
|
||||||
self.assertEqual(msg.get_payload(), [])
|
self.assertEqual(msg.get_payload(), [])
|
||||||
|
|
||||||
|
def test_attach_when_payload_is_string(self):
|
||||||
|
msg = Message()
|
||||||
|
msg['Content-Type'] = 'multipart/mixed'
|
||||||
|
msg.set_payload('string payload')
|
||||||
|
sub_msg = MIMEMessage(Message())
|
||||||
|
self.assertRaisesRegex(TypeError, "[Aa]ttach.*non-multipart",
|
||||||
|
msg.attach, sub_msg)
|
||||||
|
|
||||||
def test_get_charsets(self):
|
def test_get_charsets(self):
|
||||||
eq = self.assertEqual
|
eq = self.assertEqual
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1188,6 +1188,7 @@ Daniel Shahaf
|
||||||
Ha Shao
|
Ha Shao
|
||||||
Mark Shannon
|
Mark Shannon
|
||||||
Richard Shapiro
|
Richard Shapiro
|
||||||
|
Varun Sharma
|
||||||
Vlad Shcherbina
|
Vlad Shcherbina
|
||||||
Justin Sheehy
|
Justin Sheehy
|
||||||
Charlie Shepherd
|
Charlie Shepherd
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,10 @@ Core and Builtins
|
||||||
Library
|
Library
|
||||||
-------
|
-------
|
||||||
|
|
||||||
|
- Issue #11558: ``email.message.Message.attach`` now returns a more
|
||||||
|
useful error message if ``attach`` is called on a message for which
|
||||||
|
``is_multipart`` is False.
|
||||||
|
|
||||||
- Issue #20283: RE pattern methods now accept the string keyword parameters
|
- Issue #20283: RE pattern methods now accept the string keyword parameters
|
||||||
as documented. The pattern and source keyword parameters are left as
|
as documented. The pattern and source keyword parameters are left as
|
||||||
deprecated aliases.
|
deprecated aliases.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue