示例#1
0
    def from_dict(addr_dict, category=None):
        if not addr_dict:
            return None

        addr = Address()

        # Shortcut if only a string is passed as a parameter
        if not isinstance(addr_dict, dict):
            addr.address_value = String.from_dict(addr_dict)
            addr.category = category
            return addr

        if 'category' in addr_dict:
            addr.category = addr_dict['category']
        if 'is_destination' in addr_dict:
            addr.is_destination = addr_dict['is_destination']
        if 'is_source' in addr_dict:
            addr.is_source = addr_dict['is_source']
        if 'address_value' in addr_dict:
            addr.address_value = String.from_dict(addr_dict['address_value'])
        if 'ext_category' in addr_dict:
            addr.ext_category = String.from_dict(addr_dict['ext_category'])
        if 'vlan_name' in addr_dict:
            addr.vlan_name = String.from_dict(addr_dict['vlan_name'])
        if 'vlan_number' in addr_dict:
            addr.vlan_number = Integer.from_dict(addr_dict['vlan_number'])

        return addr
示例#2
0
    def test_round_trip(self):
        attr_dict = {
                        'value': "test_value",
                        'id': "test_a",
                        'idref': "test_b",
                        'datatype': "test_c",
                        'condition': "test_d",
                        'pattern_type': "test_e",
                        'regex_syntax': "test_f",
                        'start_range': "test_g",
                        'end_range': "test_h",
                        'value_set': ["test_i"],
                        'has_changed': "test_j",
                        'trend': "test_k",
                        'appears_random': "test_l",
                        'is_obfuscated': "test_m",
                        'obfuscation_algorithm_ref': "test_n",
                        'is_defanged': "test_o",
                        'defanging_algorithm_ref': "test_p",
                        'refanging_transform_type': "test_q",
                        'refanging_transform': "test_r",
                    }

        # Using `String` class explicity since the base `Attribute` class does
        # not define _get_binding_class()
        attr_obj = String.object_from_dict(attr_dict)
        attr_dict2 = String.dict_from_object(attr_obj)
        self.assertEqual(attr_dict, attr_dict2)
示例#3
0
    def from_obj(addr_object):
        if not addr_object:
            return None

        addr = Address()

        addr.address_value = String.from_obj(addr_object.get_Address_Value())
        addr.category = addr_object.get_category()
        addr.is_destination = addr_object.get_is_destination()
        addr.is_source = addr_object.get_is_source()
        addr.ext_category = String.from_obj(addr_object.get_Ext_Category())
        addr.vlan_name = String.from_obj(addr_object.get_VLAN_Name())
        addr.vlan_num = Integer.from_obj(addr_object.get_VLAN_Num())

        return addr