当前位置: 首页>>代码示例>>Python>>正文


Python EmailMessage.object_from_dict方法代码示例

本文整理汇总了Python中cybox.objects.email_message_object.EmailMessage.object_from_dict方法的典型用法代码示例。如果您正苦于以下问题:Python EmailMessage.object_from_dict方法的具体用法?Python EmailMessage.object_from_dict怎么用?Python EmailMessage.object_from_dict使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在cybox.objects.email_message_object.EmailMessage的用法示例。


在下文中一共展示了EmailMessage.object_from_dict方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_roundtrip_basic

# 需要导入模块: from cybox.objects.email_message_object import EmailMessage [as 别名]
# 或者: from cybox.objects.email_message_object.EmailMessage import object_from_dict [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 object_from_dict [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

示例3: object_from_dict

# 需要导入模块: from cybox.objects.email_message_object import EmailMessage [as 别名]
# 或者: from cybox.objects.email_message_object.EmailMessage import object_from_dict [as 别名]
 def object_from_dict(cls, task_attributes):
     task_obj = win_task_binding.WindowsTaskObjectType()
     task_obj.set_anyAttributes_({'xsi:type' : 'WinTaskObj:WindowsTaskObjectType'})
     
     for key, value in task_attributes.items():
         if key == 'name' and utils.test_value(value):
             task_obj.set_Name(Base_Object_Attribute.object_from_dict(common_types_binding.StringObjectAttributeType(datatype='String'), value))
         if key == 'status' and utils.test_value(value):
             task_obj.set_Status(Base_Object_Attribute.object_from_dict(win_task_binding.TaskStatusType(), value))
         if key == 'priority' and utils.test_value(value):
             task_obj.set_Priority(Base_Object_Attribute.object_from_dict(win_task_binding.TaskPriorityType(), value))
         if key == 'flags' and utils.test_value(value):
             task_obj.set_Flags(Base_Object_Attribute.object_from_dict(win_task_binding.TaskFlagType(), value))
         if key == 'application_type' and utils.test_value(value):
             task_obj.set_Application_Name(Base_Object_Attribute.object_from_dict(common_types_binding.StringObjectAttributeType(datatype='String'), value))
         if key == 'paramters' and utils.test_value(value):
             task_obj.set_Parameters(Base_Object_Attribute.object_from_dict(common_types_binding.StringObjectAttributeType(datatype='String'), value))
         if key == 'account_name' and utils.test_value(value):
             tdfasd;fask_obj.set_Account_Name(Base_Object_Attribute.object_from_dict(common_types_binding.StringObjectAttributeType(datatype='String'), value))
         if key == 'account_run_level' and utils.test_value(value):
             task_obj.set_Account_Run_Level(Base_Object_Attribute.object_from_dict(common_types_binding.StringObjectAttributeType(datatype='String'), value))
         if key == 'account_Logon_Type' and utils.test_value(value):
             task_obj.set_Account_Logon_Type(Base_Object_Attribute.object_from_dict(common_types_binding.StringObjectAttributeType(datatype='String'), value))
         if key == 'account_name' and utils.test_value(value):
             task_obj.set_Account_Name(Base_Object_Attribute.object_from_dict(common_types_binding.StringObjectAttributeType(datatype='String'), value))
         if key == 'creator' and utils.test_value(value):
             task_obj.set_Creator(Base_Object_Attribute.object_from_dict(common_types_binding.StringObjectAttributeType(datatype='String'), value))
         if key == 'comment' and utils.test_value(value):
             task_obj.set_Comment(Base_Object_Attribute.object_from_dict(common_types_binding.StringObjectAttributeType(datatype='String'), value))
         if key == 'working_directory' and utils.test_value(value):
             task_obj.set_Working_Directory(Base_Object_Attribute.object_from_dict(common_types_binding.StringObjectAttributeType(datatype='String'), value))
         if key == 'creation_date' and utils.test_value(value):
             task_obj.set_Creation_Date(Base_Object_Attribute.object_from_dict(common_types_binding.DateTimeObjectAttributeType(datatype='DateTime'), value))
         if key == 'most_recent_run_time' and utils.test_value(value):
             task_obj.set_Most_Recent_Run_Time(Base_Object_Attribute.object_from_dict(common_types_binding.DateTimeObjectAttributeType(datatype='DateTime'), value))
         if key == 'next_run_time' and utils.test_value(value):
             task_obj.set_Next_Run_Time(Base_Object_Attribute.object_from_dict(common_types_binding.DateTimeObjectAttributeType(datatype='DateTime'), value))
         if key == 'exit_code' and utils.test_value(value):
             task_obj.set_Exit_Code(Base_Object_Attribute.object_from_dict(common_types_binding.LongObjectAttributeType(datatype='Long'), value))
         if key == 'max_run_time' and utils.test_value(value):
             task_obj.set_Max_Run_Time(Base_Object_Attribute.object_from_dict(common_types_binding.UnsignedLongObjectAttributeType(datatype='UnsignedLong'), value))
         if key == 'work_item_data' and utils.test_value(value):
             task_obj.set_Work_Item_Data(Base_Object_Attribute.object_from_dict(common_types_binding.Base64BinaryObjectAttributeType(datatype='Base64Binary'), value))
         if key == 'action_list' and utils.test_value(value):
             action_list = win_task_binding.TaskActionListType()
             for action in value:
                 action_obj = win_task_binding.TaskActionType()
                 for action_key, action_value in action.items():
                     if action_key == 'action_type' and utils.test_value(action_value):
                         action_obj.set_Action_Type(Base_Object_Attribute.object_from_dict(win_task_binding.TaskActionTypeType(), action_value))
                     if action_key == 'action_id' and utils.test_value(action_value):
                         action_obj.set_Action_ID(Base_Object_Attribute.object_from_dict(common_types_binding.StringObjectAttributeType(datatype='String'), action_value))
                     if action_key == 'iemailaction' and utils.test_value(action_value):
                         action_obj.set_IEmailAction(EmailMessage.object_from_dict(action_value))
                     if action_key == 'icomhandleraction' and utils.test_value(action_value):
                         icom_obj = win_task_binding.IComHandlerActionType()
                         for icom_key, icom_value in action_value.items():
                             if icom_key == 'com_data' and utils.test_value(icom_value):
                                 icom_obj.set_COM_Data(Base_Object_Attribute.object_from_dict(common_types_binding.StringObjectAttributeType(datatype='String'), icom_value))
                             if icom_key == 'com_class_id' and utils.test_value(icom_value):
                                 icom_obj.set_COM_Class_ID(Base_Object_Attribute.object_from_dict(common_types_binding.StringObjectAttributeType(datatype='String'), icom_value))
                         action_obj.set_IComHandlerAction(icom_obj)
                     if action_key == 'iexecaction' and utils.test_value(action_value):
                         iexec_obj = win_task_binding.IExecActionType()
                         for iexec_key, iexec_value in action_value.items():
                             if iexec_key == 'exec_arguments' and utils.test_value(iexec_value):
                                 iexec_obj.set_Exec_Arguments(Base_Object_Attribute.object_from_dict(common_types_binding.StringObjectAttributeType(datatype='String'), iexec_value))
                             if iexec_key == 'exec_program_path' and utils.test_value(iexec_value):
                                 iexec_obj.set_Exec_Program_Path(Base_Object_Attribute.object_from_dict(common_types_binding.StringObjectAttributeType(datatype='String'), iexec_value))
                             if iexec_key == 'exec_working_directorys' and utils.test_value(iexec_value):
                                 iexec_obj.set_Exec_Working_Directory(Base_Object_Attribute.object_from_dict(common_types_binding.StringObjectAttributeType(datatype='String'), iexec_value))
                             if iexec_key == 'exec_program_hashes' and utils.test_value(iexec_value):
                                 iexec_obj.set_Exec_Arguments(HashList.object_from_dict(iexec_value))
                         action_obj.set_IExecAction(iexec_obj)
                     if action_key == 'ishowmessageaction' and utils.test_value(action_value):
                         ishow_obj = win_task_binding.IShowMessageActionType()
                         for ishow_key, ishow_value in action_value.items():
                             if ishow_key == 'show_message_body' and utils.test_value(ishow_value):
                                 ishow_obj.set_Show_Message_Body(Base_Object_Attribute.object_from_dict(common_types_binding.StringObjectAttributeType(datatype='String'), ishow_value))
                             if ishow_key == 'show_message_title' and utils.test_value(ishow_value):
                                 ishow_obj.set_Show_Message_Title(Base_Object_Attribute.object_from_dict(common_types_binding.StringObjectAttributeType(datatype='String'), ishow_value))
                         action_obj.set_IShowMessageAction(ishow_obj)
                 action_list.add_Action(action_obj)
             task_obj.set_Action_List(action_list)
         if key == 'trigger_list' and utils.test_value(value):           
             trigger_list = win_task_binding.TriggerListType()
             for trigger in value:
                 trigger_obj = win_task_binding.TriggerType()
                 for trigger_key, trigger_value in trigger.items():
                     if trigger_key == 'trigger_begin' and utils.test_value(trigger_value):
                         trigger_obj.set_Trigger_Begin(common_types_binding.DateTimeObjectAttributeType(datatype='DateTime'), trigger_value)
                     if trigger_key == 'trigger_end' and utils.test_value(trigger_value):
                         trigger_obj.set_Trigger_End(common_types_binding.DateTimeObjectAttributeType(datatype='DateTime'), trigger_value)
                     if trigger_key == 'trigger_delay' and utils.test_value(trigger_value):
                         trigger_obj.set_Trigger_Begin(common_types_binding.DurationObjectAttributeType(datatype='Duration'), trigger_value)
                     if trigger_key == 'trigger_max_run_time' and utils.test_value(trigger_value):
                         trigger_obj.set_Max_Run_Time(common_types_binding.DurationObjectAttributeType(datatype='Duration'), trigger_value)
                     if trigger_key == 'trigger_session_change_type' and utils.test_value(trigger_value):
                         trigger_obj.set_Trigger_Session_Change_Type(Base_Object_Attribute.object_from_dict(common_types_binding.StringObjectAttributeType(datatype='String'), trigger_value))
                     if trigger_key == 'trigger_type' and utils.test_value(trigger_value):
#.........这里部分代码省略.........
开发者ID:2xyo,项目名称:python-cybox,代码行数:103,代码来源:win_task_object.py


注:本文中的cybox.objects.email_message_object.EmailMessage.object_from_dict方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。