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


Python dictdiffer.diff方法代码示例

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


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

示例1: diff_round_tripped

# 需要导入模块: import dictdiffer [as 别名]
# 或者: from dictdiffer import diff [as 别名]
def diff_round_tripped(self, original, round_tripped, ignore_fields=[]):
        differ = False
        for diff_type, field_path, values in list(
                dictdiffer.diff(round_tripped.toJsonDict(), original.toJsonDict())):
            if type(field_path).__name__ in ['unicode', 'str']:
                field_path = [field_path]
            if self.is_field_ignored(field_path, ignore_fields):
                continue
            expected = values[1] if len(values) > 1 else None
            observed = values[0]
            if observed in self._empty_values and expected in self._empty_values:
                continue
            if self.is_hashable(expected) and self._equal_values.get(expected, "not the same") == observed:
                continue
            if expected == observed:
                continue
            logging.error("{}: {} expected '{}' found '{}'".format(diff_type, ".".join(
                list(map(str, field_path))), expected, observed))
            differ = True
        return differ 
开发者ID:genomicsengland,项目名称:GelReportModels,代码行数:22,代码来源:base_test_migration.py

示例2: build_instance_config_diff

# 需要导入模块: import dictdiffer [as 别名]
# 或者: from dictdiffer import diff [as 别名]
def build_instance_config_diff(instance_config: 'BetaTestApplication'):
    """
    Builds an configuration diff for the provided instance configuration.
    """
    instance = instance_config.instance
    if not instance:
        instance = object()
    original_config = {}
    new_config = {}
    for attr in ('instance_name', 'privacy_policy_url', 'public_contact_email'):
        original_config[attr] = getattr(instance, attr, None)
        new_config[attr] = getattr(instance_config, attr, None)

    original_config['theme_config'] = getattr(instance, 'theme_config', None) or {}
    new_config['theme_config'] = instance_config.draft_theme_config or {}
    original_config['static_content_overrides'] = getattr(instance, 'static_content_overrides', None) or {}
    new_config['static_content_overrides'] = instance_config.draft_static_content_overrides or {}

    return list(diff(original_config, new_config)) 
开发者ID:open-craft,项目名称:opencraft,代码行数:21,代码来源:utils.py

示例3: _diff_dicts

# 需要导入模块: import dictdiffer [as 别名]
# 或者: from dictdiffer import diff [as 别名]
def _diff_dicts(active, current, ignore=('changed',)):
        res = {}

        for t, key, value in diff(active, current, ignore=ignore):
            if t not in res:
                res[t] = {}

            if t == 'change':
                if isinstance(key, list):  # list value has changed
                    key = key[0]
                    value = (active[key], current[key])

                res[t][key] = value
            else:  # add, remove
                if key:  # list value has changed
                    if 'change' not in res:
                        res['change'] = {}
                    res['change'][key] = (active[key], current[key])
                else:
                    for k, v in value:
                        res[t][k] = v

        return res 
开发者ID:erigones,项目名称:esdc-ce,代码行数:25,代码来源:api_views.py

示例4: _diff_lists

# 需要导入模块: import dictdiffer [as 别名]
# 或者: from dictdiffer import diff [as 别名]
def _diff_lists(active, current, ignore=()):
        res = {}

        for t, key, value in diff(active, current, ignore=ignore):
            if t not in res:
                res[t] = {}

            if t == 'change':
                list_id, attr = key
                list_id += 1

                if list_id not in res[t]:
                    res[t][list_id] = {}

                res[t][list_id][attr] = value

            else:  # add, remove
                for list_id, full_value in value:
                    res[t][list_id + 1] = full_value

        return res 
开发者ID:erigones,项目名称:esdc-ce,代码行数:23,代码来源:api_views.py

示例5: get_embed_dict_differences

# 需要导入模块: import dictdiffer [as 别名]
# 或者: from dictdiffer import diff [as 别名]
def get_embed_dict_differences(embed1: dict, embed2: dict) -> list:
    """Finds any differences between 2 embed dicts, returning the names of the keys /
    fields that are different. Does not find additions or deletions, just changes.

    Args:
        embed1: A dict of a discord Embed object.
        embed2: A dict of a discord Embed object.

    Returns:
        A List of strings that are the names of the changed keys / fields.

    """
    changes = []

    for difference in list(diff(embed1, embed2)):

        # The first index is the type of diff. We are looking for changes.
        if difference[0] == "change":
            if difference[1] == "image.url":
                # Ignore image url changes.
                continue

            # The second index ([1]) is the key, or in the case of fields, it is a list
            # like: ['fields', 0, 'value'].
            # Here we check it is a fields value that has changed, otherwise ignore it.
            if (
                isinstance(difference[1], list)
                and difference[1][0] == "fields"
                and difference[1][2] == "value"
            ):
                # diff[1][1] is the fields index in the embed dict.
                changes.append(embed1["fields"][difference[1][1]]["name"])

            else:
                changes.append(difference[1])

    return changes 
开发者ID:r-spacex,项目名称:SpaceXLaunchBot,代码行数:39,代码来源:notifications.py

示例6: equals

# 需要导入模块: import dictdiffer [as 别名]
# 或者: from dictdiffer import diff [as 别名]
def equals(self, instance):
        """
        Method to compare entities
        :return:
        """
        if not isinstance(instance, ProtocolElement):
            logging.error("Comparing instance of type {} with instance of type {}".format(type(self), type(instance)))
            return False
        differences = list(dictdiffer.diff(self.toJsonDict(), instance.toJsonDict()))
        if differences is None or differences == []:
            return True
        return differences 
开发者ID:genomicsengland,项目名称:GelReportModels,代码行数:14,代码来源:protocol.py

示例7: patch_dict

# 需要导入模块: import dictdiffer [as 别名]
# 或者: from dictdiffer import diff [as 别名]
def patch_dict(original_dict: dict, patch_dictionary: dict) -> dict:
    """Patches a dict with another. Patching means that any path defines in the
    patch is either added (if it does not exist), or replaces the existing value (if
    it exists). Nothing is removed from the original dict, only added/replaced.

    Parameters
    ----------
    original_dict : dict
        Base dictionary which will get paths added/changed
    patch_dictionary: dict
        Dictionary which will be overlaid on top of original_dict

    Examples
    --------
    >>> patch_dict({"highKey":{"lowkey1":1, "lowkey2":2}}, {"highKey":{"lowkey1":10}})
    {'highKey': {'lowkey1': 10, 'lowkey2': 2}}
    >>> patch_dict({"highKey":{"lowkey1":1, "lowkey2":2}}, {"highKey":{"lowkey3":3}})
    {'highKey': {'lowkey1': 1, 'lowkey2': 2, 'lowkey3': 3}}
    >>> patch_dict({"highKey":{"lowkey1":1, "lowkey2":2}}, {"highKey2":4})
    {'highKey': {'lowkey1': 1, 'lowkey2': 2}, 'highKey2': 4}

    Returns
    -------
    dict
        A new dictionary which is the result of overlaying `patch_dictionary` on top of
        `original_dict`

    """
    diff = dictdiffer.diff(original_dict, patch_dictionary)
    adds_and_mods = [(f, d, s) for (f, d, s) in diff if f != "remove"]
    return dictdiffer.patch(adds_and_mods, original_dict) 
开发者ID:equinor,项目名称:gordo,代码行数:33,代码来源:helpers.py

示例8: import_feature_template_list

# 需要导入模块: import dictdiffer [as 别名]
# 或者: from dictdiffer import diff [as 别名]
def import_feature_template_list(self, feature_template_list, check_mode=False, update=False):
        """Import a list of feature templates from list to vManage.  Object Names are converted to IDs.


        Args:
            feature_template_list (list): List of feature templates
            check_mode (bool): Only check to see if changes would be made
            update (bool): Update the template if it exists

        Returns:
            result (list): Returns the diffs of the updates.

        """
        # Process the feature templates
        feature_template_updates = []
        feature_template_dict = self.feature_templates.get_feature_template_dict(factory_default=True, remove_key=False)
        for feature_template in feature_template_list:
            if 'templateId' in feature_template:
                feature_template.pop('templateId')
            if feature_template['templateName'] in feature_template_dict:
                existing_template = feature_template_dict[feature_template['templateName']]
                feature_template['templateId'] = existing_template['templateId']
                diff = list(
                    dictdiffer.diff(existing_template['templateDefinition'], feature_template['templateDefinition']))
                if len(diff):
                    feature_template_updates.append({'name': feature_template['templateName'], 'diff': diff})
                    if not check_mode and update:
                        self.feature_templates.update_feature_template(feature_template)
            else:
                diff = list(dictdiffer.diff({}, feature_template['templateDefinition']))
                feature_template_updates.append({'name': feature_template['templateName'], 'diff': diff})
                if not check_mode:
                    self.feature_templates.add_feature_template(feature_template)

        return feature_template_updates 
开发者ID:CiscoDevNet,项目名称:python-viptela,代码行数:37,代码来源:template_data.py

示例9: import_local_policy_list

# 需要导入模块: import dictdiffer [as 别名]
# 或者: from dictdiffer import diff [as 别名]
def import_local_policy_list(self, local_policy_list, update=False, push=False, check_mode=False, force=False):
        """Import Local Policies into vManage.  Object names are converted to IDs.

        Returns:
            response (dict): A list of all policy lists currently
                in vManage.

        """
        local_policy_dict = self.local_policy.get_local_policy_dict(remove_key=False)
        diff = []
        local_policy_updates = []
        for local_policy in local_policy_list:
            payload = {'policyName': local_policy['policyName']}
            payload['policyDescription'] = local_policy['policyDescription']
            payload['policyType'] = local_policy['policyType']
            payload['policyDefinition'] = local_policy['policyDefinition']
            if payload['policyName'] in local_policy_dict:
                # A policy by that name already exists
                existing_policy = self.convert_policy_to_name(local_policy_dict[payload['policyName']])
                diff_ignore = set([
                    'lastUpdated', 'policyVersion', 'createdOn', 'references', 'isPolicyActivated', '@rid', 'policyId',
                    'createdBy', 'lastUpdatedBy', 'lastUpdatedOn', 'mastersAttached', 'policyDefinitionEdit',
                    'devicesAttached'
                ])
                diff = list(dictdiffer.diff(existing_policy, payload, ignore=diff_ignore))
                if diff:
                    print(diff)
                    local_policy_updates.append({'name': local_policy['policyName'], 'diff': diff})
                    if 'policyDefinition' in payload:
                        self.convert_definition_name_to_id(payload['policyDefinition'])
                    if not check_mode and update:
                        self.local_policy.update_local_policy(payload, existing_policy['policyId'])
            else:
                diff = list(dictdiffer.diff({}, payload['policyDefinition']))
                local_policy_updates.append({'name': local_policy['policyName'], 'diff': diff})
                if 'policyDefinition' in payload:
                    # Convert list and definition names to template IDs
                    self.convert_definition_name_to_id(payload['policyDefinition'])
                if not check_mode:
                    self.local_policy.add_local_policy(payload)
        return local_policy_updates 
开发者ID:CiscoDevNet,项目名称:python-viptela,代码行数:43,代码来源:policy_data.py

示例10: _check_format

# 需要导入模块: import dictdiffer [as 别名]
# 或者: from dictdiffer import diff [as 别名]
def _check_format(self):
        """
        检查配置格式, 使用默认配置代替丢失/错误配置
        """
        with open(self._main_path + "/config.default.yaml", "r") as f:
            origin_config = yaml.load(f, Loader=yaml.FullLoader)

        keys = []
        diff = dictdiffer.diff(origin_config, self.config_dict)
        for item in diff:
            if item[0] == "remove":
                for diff_item in item[2]:
                    key = diff_item[0]
                    keys.append(key)
                    print("[!] Missing config item: {}, use default.".format(key))
            elif item[0] == "change" and not isinstance(item[2][0], type(item[2][1])):
                # 配置只有一层,只取[0]即可
                key = item[1][0]
                keys.append(key)
                print("[!] Config item {} type error, expect {}, found {}, use default value.".format(
                    item[1], type(item[2][0]), type(item[2][1])))
            elif item[0] == "add":
                for diff_item in item[2]:
                    key = diff_item[0]
                    print("[!] Unknow config item {}, ignore.".format(key))
                continue
            else:
                continue
        for key in keys:
            self.config_dict[key] = origin_config[key] 
开发者ID:baidu-security,项目名称:openrasp-iast,代码行数:32,代码来源:config.py

示例11: is_diff

# 需要导入模块: import dictdiffer [as 别名]
# 或者: from dictdiffer import diff [as 别名]
def is_diff(self, data):
        return self.request.method == 'GET' and self.request.query_params.get('diff', False) 
开发者ID:erigones,项目名称:esdc-ce,代码行数:4,代码来源:api_views.py

示例12: diff

# 需要导入模块: import dictdiffer [as 别名]
# 或者: from dictdiffer import diff [as 别名]
def diff(self):
        if self._diff is None:
            self._diff = self.is_diff(self.data)
        return self._diff 
开发者ID:erigones,项目名称:esdc-ce,代码行数:6,代码来源:api_views.py

示例13: import_device_template_list

# 需要导入模块: import dictdiffer [as 别名]
# 或者: from dictdiffer import diff [as 别名]
def import_device_template_list(self, device_template_list, check_mode=False, update=False):
        """Import a list of device templates from list to vManage.  Object Names are converted to IDs.


        Args:
            device_template_list (list): List of device templates
            check_mode (bool): Only check to see if changes would be made
            update (bool): Update the template if it exists

        Returns:
            result (list): Returns the diffs of the updates.

        """
        device_template_updates = []
        device_template_dict = self.device_templates.get_device_template_dict()
        diff = []
        for device_template in device_template_list:
            if 'policyId' in device_template:
                device_template.pop('policyId')
            if 'securityPolicyId' in device_template:
                device_template.pop('securityPolicyId')
            if device_template['templateName'] in device_template_dict:
                existing_template = self.convert_device_template_to_name(
                    device_template_dict[device_template['templateName']])
                device_template['templateId'] = existing_template['templateId']
                # Just check the things that we care about changing.
                diff_ignore = set([
                    'templateId', 'policyId', 'connectionPreferenceRequired', 'connectionPreference', 'templateName',
                    'attached_devices', 'input', 'securityPolicyId'
                ])
                diff = list(dictdiffer.diff(existing_template, device_template, ignore=diff_ignore))
                if len(diff):
                    device_template_updates.append({'name': device_template['templateName'], 'diff': diff})
                    if not check_mode and update:
                        if not check_mode:
                            converted_device_template = self.convert_device_template_to_id(device_template)
                            self.device_templates.update_device_template(converted_device_template)
            else:
                if 'generalTemplates' in device_template:
                    diff = list(dictdiffer.diff({}, device_template['generalTemplates']))
                elif 'templateConfiguration' in device_template:
                    diff = list(dictdiffer.diff({}, device_template['templateConfiguration']))
                else:
                    raise Exception("Template {0} is of unknown type".format(device_template['templateName']))
                device_template_updates.append({'name': device_template['templateName'], 'diff': diff})
                if not check_mode:
                    converted_device_template = self.convert_device_template_to_id(device_template)
                    self.device_templates.add_device_template(converted_device_template)

        return device_template_updates 
开发者ID:CiscoDevNet,项目名称:python-viptela,代码行数:52,代码来源:template_data.py

示例14: import_policy_list_list

# 需要导入模块: import dictdiffer [as 别名]
# 或者: from dictdiffer import diff [as 别名]
def import_policy_list_list(self, policy_list_list, push=False, update=False, check_mode=False, force=False):
        """Import a list of policyies lists into vManage.  Object Names are translated to IDs.

        Args:
            policy_list_list: A list of polcies
            push (bool): Whether to push a change out
            update (bool): Whether to update when the list exists
            check_mode (bool): Report what updates would happen, but don't update

        Returns:
            result (dict): All data associated with a response.

        """

        # Policy Lists
        diff = []
        policy_list_updates = []
        #pylint: disable=too-many-nested-blocks
        for policy_list in policy_list_list:
            policy_list_dict = self.policy_lists.get_policy_list_dict(policy_list['type'],
                                                                      remove_key=False,
                                                                      cache=False)
            if policy_list['name'] in policy_list_dict:
                existing_list = policy_list_dict[policy_list['name']]
                diff_ignore = set(
                    ['listId', 'references', 'lastUpdated', 'activatedId', 'policyId', 'listId', 'isActivatedByVsmart'])
                diff = list(dictdiffer.diff(existing_list, policy_list, ignore=diff_ignore))
                if diff:
                    policy_list_updates.append({'name': policy_list['name'], 'diff': diff})
                    policy_list['listId'] = policy_list_dict[policy_list['name']]['listId']
                    # If description is not specified, try to get it from the existing information
                    if not policy_list['description']:
                        policy_list['description'] = policy_list_dict[policy_list['name']]['description']
                    if not check_mode and update:
                        response = self.policy_lists.update_policy_list(policy_list)

                        if response['json']:
                            # Updating the policy list returns a `processId` that locks the list and 'masterTemplatesAffected'
                            # that lists the templates affected by the change.
                            if 'error' in response['json']:
                                raise Exception(response['json']['error']['message'])
                            elif 'processId' in response['json']:
                                if push:
                                    vmanage_device_templates = DeviceTemplates(self.session, self.host)
                                    # If told to push out the change, we need to reattach each template affected by the change
                                    for template_id in response['json']['masterTemplatesAffected']:
                                        vmanage_device_templates.reattach_device_template(template_id)
                            else:
                                raise Exception("Did not get a process id when updating policy list")
            else:
                diff = list(dictdiffer.diff({}, policy_list))
                policy_list_updates.append({'name': policy_list['name'], 'diff': diff})
                if not check_mode:
                    self.policy_lists.add_policy_list(policy_list)

        return policy_list_updates 
开发者ID:CiscoDevNet,项目名称:python-viptela,代码行数:58,代码来源:policy_data.py

示例15: import_policy_definition_list

# 需要导入模块: import dictdiffer [as 别名]
# 或者: from dictdiffer import diff [as 别名]
def import_policy_definition_list(self,
                                      policy_definition_list,
                                      update=False,
                                      push=False,
                                      check_mode=False,
                                      force=False):
        """Import Policy Definitions into vManage.  Object names are converted to IDs.

        Returns:
            response (dict): A list of all policy lists currently
                in vManage.

        """
        policy_definition_updates = []
        for definition in policy_definition_list:
            policy_definition_dict = self.policy_definitions.get_policy_definition_dict(definition['type'],
                                                                                        remove_key=False)
            diff = []
            payload = {
                "name": definition['name'],
                "description": definition['description'],
                "type": definition['type'],
            }
            if 'defaultAction' in definition:
                payload.update({'defaultAction': definition['defaultAction']})
            if 'sequences' in definition:
                payload.update({'sequences': definition['sequences']})
            if 'definition' in definition:
                payload.update({'definition': definition['definition']})

            if definition['name'] in policy_definition_dict:
                existing_definition = self.convert_policy_definition_to_name(policy_definition_dict[definition['name']])
                # Just check the things that we care about changing.
                diff_ignore = set([
                    'lastUpdated', 'definitionId', 'referenceCount', 'references', 'owner', 'isActivatedByVsmart',
                    'infoTag', 'activatedId'
                ])
                diff = list(dictdiffer.diff(existing_definition, payload, ignore=diff_ignore))
                if diff:
                    converted_definition = self.convert_policy_definition_to_id(definition)
                    policy_definition_updates.append({'name': converted_definition['name'], 'diff': diff})
                    if not check_mode and update:
                        self.policy_definitions.update_policy_definition(
                            converted_definition, policy_definition_dict[converted_definition['name']]['definitionId'])
                    policy_definition_updates.append({'name': converted_definition['name'], 'diff': diff})
            else:
                # Policy definition does not exist
                diff = list(dictdiffer.diff({}, payload))
                policy_definition_updates.append({'name': definition['name'], 'diff': diff})
                converted_definition = self.convert_policy_definition_to_id(definition)
                if not check_mode:
                    self.policy_definitions.add_policy_definition(converted_definition)

        return policy_definition_updates 
开发者ID:CiscoDevNet,项目名称:python-viptela,代码行数:56,代码来源:policy_data.py


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