當前位置: 首頁>>代碼示例>>Python>>正文


Python EmailMessage.dict_from_object方法代碼示例

本文整理匯總了Python中cybox.objects.email_message_object.EmailMessage.dict_from_object方法的典型用法代碼示例。如果您正苦於以下問題:Python EmailMessage.dict_from_object方法的具體用法?Python EmailMessage.dict_from_object怎麽用?Python EmailMessage.dict_from_object使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在cybox.objects.email_message_object.EmailMessage的用法示例。


在下文中一共展示了EmailMessage.dict_from_object方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_roundtrip_basic

# 需要導入模塊: from cybox.objects.email_message_object import EmailMessage [as 別名]
# 或者: from cybox.objects.email_message_object.EmailMessage import dict_from_object [as 別名]
    def test_roundtrip_basic(self):
        msg_dict = {
            "header": {"from": "[email protected]", "to": ["[email protected]"], "subject": "Howdy!"},
            "raw_body": "This is a test. This is only a test.",
        }
        msg_obj = EmailMessage.object_from_dict(msg_dict)
        msg_dict2 = EmailMessage.dict_from_object(msg_obj)

        # Don't want to compare dictionaries directly since email addresses
        # will have been expanded to full dictionaries with "address_value"
        # and "category"
        self.assertEqual(msg_dict2["header"]["from"]["address_value"], msg_dict["header"]["from"])
        self.assertEqual(msg_dict2["header"]["to"][0]["address_value"], msg_dict["header"]["to"][0])
        self.assertEqual(msg_dict2["header"]["subject"], msg_dict["header"]["subject"])
        self.assertEqual(msg_dict2["raw_body"], msg_dict["raw_body"])
        self.assertEqual(msg_dict2["xsi:type"], EmailMessage._XSI_TYPE)

        # Make sure extra keys didn't sneak into the output.
        self.assertFalse("attachments" in msg_dict2)
        self.assertFalse("optional_header" in msg_dict2)
        self.assertFalse("email_server" in msg_dict2)
        self.assertFalse("raw_header" in msg_dict2)
        self.assertFalse("cc" in msg_dict2["header"])
        self.assertFalse("bcc" in msg_dict2["header"])
        self.assertFalse("in_reply_to" in msg_dict2["header"])
        self.assertFalse("date" in msg_dict2["header"])
        self.assertFalse("message_id" in msg_dict2["header"])
        self.assertFalse("sender" in msg_dict2["header"])
        self.assertFalse("reply_to" in msg_dict2["header"])
        self.assertFalse("errors_to" in msg_dict2["header"])
開發者ID:clever-crow-consulting,項目名稱:python-cybox,代碼行數:32,代碼來源:email_message_test.py

示例2: test_roundtrip_basic

# 需要導入模塊: from cybox.objects.email_message_object import EmailMessage [as 別名]
# 或者: from cybox.objects.email_message_object.EmailMessage import dict_from_object [as 別名]
    def test_roundtrip_basic(self):
        msg_dict = {'header': {
                                'from': "[email protected]",
                                'to': ["[email protected]"],
                                'subject': "Howdy!"
                               },
                     'raw_body': "This is a test. This is only a test.",
                    }
        msg_obj = EmailMessage.object_from_dict(msg_dict)
        msg_dict2 = EmailMessage.dict_from_object(msg_obj)

        # Don't want to compare dictionaries directly since email addresses
        # will have been expanded to full dictionaries with "address_value"
        # and "category"
        self.assertEqual(msg_dict2['header']['from']['address_value'],
                         msg_dict['header']['from'])
        self.assertEqual(msg_dict2['header']['to'][0]['address_value'],
                         msg_dict['header']['to'][0])
        self.assertEqual(msg_dict2['header']['subject'],
                         msg_dict['header']['subject'])
        self.assertEqual(msg_dict2['raw_body'],
                         msg_dict['raw_body'])
        self.assertEqual(msg_dict2['xsi:type'], EmailMessage._XSI_TYPE)

        # Make sure extra keys didn't sneak into the output.
        self.assertFalse('attachments' in msg_dict2)
        self.assertFalse('optional_header' in msg_dict2)
        self.assertFalse('email_server' in msg_dict2)
        self.assertFalse('raw_header' in msg_dict2)
        self.assertFalse('cc' in msg_dict2['header'])
        self.assertFalse('bcc' in msg_dict2['header'])
        self.assertFalse('in_reply_to' in msg_dict2['header'])
        self.assertFalse('date' in msg_dict2['header'])
        self.assertFalse('message_id' in msg_dict2['header'])
        self.assertFalse('sender' in msg_dict2['header'])
        self.assertFalse('reply_to' in msg_dict2['header'])
        self.assertFalse('errors_to' in msg_dict2['header'])
開發者ID:juandiana,項目名稱:python-cybox,代碼行數:39,代碼來源:email_message_test.py


注:本文中的cybox.objects.email_message_object.EmailMessage.dict_from_object方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。