本文整理匯總了Python中email.errors.MultipartConversionError方法的典型用法代碼示例。如果您正苦於以下問題:Python errors.MultipartConversionError方法的具體用法?Python errors.MultipartConversionError怎麽用?Python errors.MultipartConversionError使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類email.errors
的用法示例。
在下文中一共展示了errors.MultipartConversionError方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: attach
# 需要導入模塊: from email import errors [as 別名]
# 或者: from email.errors import MultipartConversionError [as 別名]
def attach(self, payload):
"""
Add the C{payload} to the current payload list.
Also prevent from adding payloads with wrong Content-Type and from
exceeding a maximum of 2 payloads.
:param payload: The payload to be attached.
:type payload: email.message.Message
"""
# second payload's content type must be equal to the protocol
# parameter given on object creation
if len(self.get_payload()) == 1:
if payload.get_content_type() != self.get_param('protocol'):
raise errors.MultipartConversionError(
'Wrong content type %s.' % payload.get_content_type)
# prevent from adding more payloads
if len(self._payload) == 2:
raise errors.MultipartConversionError(
'Cannot have more than two subparts.')
MIMEMultipart.attach(self, payload)
示例2: attach
# 需要導入模塊: from email import errors [as 別名]
# 或者: from email.errors import MultipartConversionError [as 別名]
def attach(self, payload):
# The public API prohibits attaching multiple subparts to MIMEBase
# derived subtypes since none of them are, by definition, of content
# type multipart/*
raise errors.MultipartConversionError(
'Cannot attach additional subparts to non-multipart/*')
示例3: test_bad_multipart
# 需要導入模塊: from email import errors [as 別名]
# 或者: from email.errors import MultipartConversionError [as 別名]
def test_bad_multipart(self):
eq = self.assertEqual
msg1 = Message()
msg1['Subject'] = 'subpart 1'
msg2 = Message()
msg2['Subject'] = 'subpart 2'
r = MIMEMessage(msg1)
self.assertRaises(errors.MultipartConversionError, r.attach, msg2)
示例4: test_bad_multipart
# 需要導入模塊: from email import errors [as 別名]
# 或者: from email.errors import MultipartConversionError [as 別名]
def test_bad_multipart(self):
msg1 = Message()
msg1['Subject'] = 'subpart 1'
msg2 = Message()
msg2['Subject'] = 'subpart 2'
r = MIMEMessage(msg1)
self.assertRaises(errors.MultipartConversionError, r.attach, msg2)