コード例 #1
0
ファイル: socket_object.py プロジェクト: 2xyo/python-cybox
    def object_from_dict(cls, socket_dict):
        """Create the Socket Object object representation from an input dictionary"""
        socket_obj = socket_binding.socket_objectType()
        socket_obj.set_anyAttributes_({'xsi:type' : 'socket_obj:socket_objectType'})
        
        for key, value in socket_dict.items():
            if key == 'is_blocking' and utils.test_value(value):
                socket_obj.set_is_blocking(value.get('value'))
            elif key == 'is_listening' and utils.test_value(value):
                socket_obj.set_is_listening(value.get('value'))
            elif key == 'address_family' and utils.test_value(value):
                socket_obj.set_Address_Family(Base_Object_Attribute.object_from_dict(common_types_binding.StringObjectAttributeType(datatype='String'), value))
            elif key == 'domain' and utils.test_value(value):
                socket_obj.set_Domain(Base_Object_Attribute.object_from_dict(common_types_binding.StringObjectAttributeType(datatype='String'), value))
            elif key == 'local_address':
                socket_address_obj = socket_binding.SocketAddressType()
                for local_address_key, local_address_value in value.items():
                    if local_address_key == 'ip_address' :
                        ip_address_obj = Address.create_from_dict(local_address_value)
                        if ip_address_obj.hasContent_() : socket_address_obj.set_IP_Address(ip_address_obj)
                    elif local_address_key == 'port' :
                        port_obj = Port.create_from_dict(local_address_value)
                        if port_obj.hasContent_() : socket_address_obj.set_Port(port_obj)
                if socket_address_obj.hasContent_() : socket_obj.set_Local_Address(socket_address_obj)
            elif key == 'options':
                socket_options_obj = cls.__socket_options_object_from_dict(value)
                if socket_options_obj.hasContent_() : socket_obj.set_Options(socket_options_obj)
            elif key == 'protocol' and utils.test_value(value):
                socket_obj.set_Protocol(Base_Object_Attribute.object_from_dict(common_types_binding.StringObjectAttributeType(datatype='String'), value))
            elif key == 'remote_address' and utils.test_value(value):
                socket_address_obj = socket_binding.SocketAddressType()
                for remote_address_key, remote_address_value in value.items():
                    if remote_address_key == 'ip_address' :
                        ip_address_obj = Address.create_from_dict(remote_address_value)
                        if ip_address_obj.hasContent_() : socket_address_obj.set_IP_Address(ip_address_obj)
                    elif remote_address_key == 'port' :
                        port_obj = Port.create_from_dict(remote_address_value)
                        if port_obj.hasContent_() : socket_address_obj.set_Port(port_obj)
                if socket_address_obj.hasContent_() : socket_obj.set_Remote_Address(socket_address_obj)
            elif key == 'type' and utils.test_value(value):
                socket_obj.set_Type(Base_Object_Attribute.object_from_dict(common_types_binding.StringObjectAttributeType(datatype='String'), value))

        return socket_obj