我们从Python开源项目中,提取了以下35个代码示例,用于说明如何使用email.errors.MultipartConversionError()。
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)
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/*')
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)
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 """ # first payload's content type must be equal to the protocol parameter # given on object creation if len(self._payload) == 0: if payload.get_content_type() != self.get_param('protocol'): raise errors.MultipartConversionError( 'Wrong content type.') # second payload is always application/octet-stream if len(self._payload) == 1: if payload.get_content_type() != 'application/octet-stream': 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) # # RFC 3156: application/pgp-encrypted, application/pgp-signed and # application-pgp-signature. #
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)