Diff Data Objects
513017
def DiffDataObjects(self, oldObj, newObj):
      """"""
      if oldObj == newObj:
         return True
      if not oldObj or not newObj:
         __Log__.debug('DiffDataObjects: One of the objects in None')
         return False
      oldType = Type(oldObj)
      newType = Type(newObj)
      if oldType != newType:
         __Log__.debug(
            'DiffDataObjects: Types do not match for dataobjects. %s != %s'
            % (oldObj._wsdlName, newObj._wsdlName))
         return False
      for prop in oldObj._GetPropertyList():
         oldProp = getattr(oldObj, prop.name)
         newProp = getattr(newObj, prop.name)
         propType = oldObj._GetPropertyInfo(prop.name).type
         if not oldProp and not newProp:
            continue
         elif ((prop.flags & VmomiSupport.F_OPTIONAL) and
               self._looseMatch and (not newProp or not oldProp)):
            continue
         elif not oldProp or not newProp:
            __Log__.debug(
               'DiffDataObjects: One of the objects has property %s unset'
               % prop.name)
            return False

         bMatch = True
         if IsPrimitiveType(oldProp):
            bMatch = oldProp == newProp
         elif isinstance(oldProp, types.ManagedObject):
            bMatch = self.DiffAnyObjects(oldProp, newProp, prop.flags
               & VmomiSupport.F_LINK)
         elif isinstance(oldProp, types.DataObject):
            if prop.flags & VmomiSupport.F_LINK:
               bMatch = oldObj.GetKey() == newObj.GetKey()
               LogIf(not bMatch, 'DiffDataObjects: Key match failed %s != %s'
                  % (oldObj.GetKey(), newObj.GetKey()))
            else:
               bMatch = self.DiffAnyObjects(oldProp, newProp, prop.flags
                  & VmomiSupport.F_LINK)
         elif isinstance(oldProp, list):
            bMatch = self.DiffArrayObjects(oldProp, newProp, prop.flags
               & VmomiSupport.F_LINK)
         else:
            raise TypeError("Unknown type: "+repr(propType))

         if not bMatch:
            __Log__.debug('DiffDataObjects: Objects differ in property %s'
               % prop.name)
            return False
      return True
1325701
def __diff_dict(self,
                    level,
                    parents_ids=frozenset({}),
                    print_as_attribute=False,
                    override=False,
                    override_t1=None,
                    override_t2=None):
        """"""
        if override:
            # for special stuff like custom objects and named tuples we receive preprocessed t1 and t2
            # but must not spoil the chain (=level) with it
            t1 = override_t1
            t2 = override_t2
        else:
            t1 = level.t1
            t2 = level.t2

        if print_as_attribute:
            item_added_key = "attribute_added"
            item_removed_key = "attribute_removed"
            rel_class = AttributeRelationship
        else:
            item_added_key = "dictionary_item_added"
            item_removed_key = "dictionary_item_removed"
            rel_class = DictRelationship

        t1_keys = set(t1.keys())
        t2_keys = set(t2.keys())
        if self.ignore_string_type_changes or self.ignore_numeric_type_changes:
            t1_clean_to_keys = self.__get_clean_to_keys_mapping(keys=t1_keys, level=level)
            t2_clean_to_keys = self.__get_clean_to_keys_mapping(keys=t2_keys, level=level)
            t1_keys = set(t1_clean_to_keys.keys())
            t2_keys = set(t2_clean_to_keys.keys())
        else:
            t1_clean_to_keys = t2_clean_to_keys = None

        t_keys_intersect = t2_keys.intersection(t1_keys)

        t_keys_added = t2_keys - t_keys_intersect
        t_keys_removed = t1_keys - t_keys_intersect

        for key in t_keys_added:
            key = t2_clean_to_keys[key] if t2_clean_to_keys else key
            change_level = level.branch_deeper(
                notpresent,
                t2[key],
                child_relationship_class=rel_class,
                child_relationship_param=key)
            self.__report_result(item_added_key, change_level)

        for key in t_keys_removed:
            key = t1_clean_to_keys[key] if t1_clean_to_keys else key
            change_level = level.branch_deeper(
                t1[key],
                notpresent,
                child_relationship_class=rel_class,
                child_relationship_param=key)
            self.__report_result(item_removed_key, change_level)

        for key in t_keys_intersect:  # key present in both dicts - need to compare values
            key1 = t1_clean_to_keys[key] if t1_clean_to_keys else key
            key2 = t2_clean_to_keys[key] if t2_clean_to_keys else key
            item_id = id(t1[key1])
            if parents_ids and item_id in parents_ids:
                continue
            parents_ids_added = add_to_frozen_set(parents_ids, item_id)

            # Go one level deeper
            next_level = level.branch_deeper(
                t1[key1],
                t2[key2],
                child_relationship_class=rel_class,
                child_relationship_param=key)
            self.__diff(next_level, parents_ids_added)
1316764
def join(cls, diffs: Iterable['DBDiff']) -> 'DBDiff':
        
        tracker = DBDiffTracker()
        for diff in diffs:
            diff.apply_to(tracker)
        return tracker.diff()
590291
def compare_dicts(d1, d2):
    
    a = json.dumps(d1, indent=4, sort_keys=True)
    b = json.dumps(d2, indent=4, sort_keys=True)
    # stolen from cpython
    # https://github.com/python/cpython/blob/01fd68752e2d2d0a5f90ae8944ca35df0a5ddeaa/Lib/unittest/case.py#L1091
    diff = ('\n' + '\n'.join(difflib.ndiff(
                   a.splitlines(),
                   b.splitlines())))
    return diff
396602
def diff(self):
        
        latest = self.latest
        current = NetJsonParser(self.json())
        return diff(current, latest)
1019528
def diff_schema(A, B):
    
    output =[]
    def _diff_schema(path, A, B):
        for k, av in A.items():
            if k == "_id" and path == ".":
                continue  # DO NOT ADD _id TO ANY SCHEMA DIFF
            bv = B[k]
            if bv == None:
                output.append((concat_field(path, k), av))
            elif av.type == bv.type:
                pass  # OK
            elif (av.type == None and bv.type == 'object') or (av.type == 'object' and bv.type == None):
                pass  # OK
            else:
                Log.warning("inconsistent types: {{typeA}} vs {{typeB}}", typeA=av.type, typeB=bv.type)
            _diff_schema(concat_field(path, k), av.properties, bv.properties)

    # what to do with conflicts?
    _diff_schema(".", A, B)
    return output
1368169
def get_dict_diff_str(d1, d2, title):
    
    added, removed, changed = get_dict_diff(d1, d2)
    lines = [title]

    if added:
        lines.append("Added attributes: %s"
                     % ['.'.join(x) for x in added])
    if removed:
        lines.append("Removed attributes: %s"
                     % ['.'.join(x) for x in removed])
    if changed:
        lines.append("Changed attributes: %s"
                     % ['.'.join(x) for x in changed])

    return '\n'.join(lines)
1180288
def _compute_diff(expected_endpoints, configured_endpoints):
    '''
    
    '''
    new_endpoints = []
    update_endpoints = []
    remove_endpoints = []

    ret = _compute_diff_ret()

    # noth configured => configure with expected endpoints
    if not configured_endpoints:
        ret.update({
            'add': expected_endpoints
        })
        return ret

    # noting expected => remove everything
    if not expected_endpoints:
        ret.update({
            'remove': configured_endpoints
        })
        return ret

    expected_endpoints_clear = _clear_ignore_list(expected_endpoints)
    configured_endpoints_clear = _clear_ignore_list(configured_endpoints)

    for expected_endpoint_clear in expected_endpoints_clear:
        if expected_endpoint_clear not in configured_endpoints_clear:
            # none equal => add or update
            matching_ele = _find_match(expected_endpoint_clear, configured_endpoints_clear)
            if not matching_ele:
                # new element => add
                new_endpoints.append(expected_endpoint_clear)
            else:
                # element matched, but some fields are different
                update_fields = _update_on_fields(matching_ele, expected_endpoint_clear)
                if update_fields:
                    update_endpoints.append(update_fields)
    for configured_endpoint_clear in configured_endpoints_clear:
        if configured_endpoint_clear not in expected_endpoints_clear:
            matching_ele = _find_match(configured_endpoint_clear, expected_endpoints_clear)
            if not matching_ele:
                #  no match found => remove
                remove_endpoints.append(configured_endpoint_clear)

    return {
        'add': new_endpoints,
        'update': update_endpoints,
        'remove': remove_endpoints
    }
329626
def get_diff(a, b, *args, **kwargs):
    '''
    
    '''
    encoding = ('utf-8', 'latin-1', __salt_system_encoding__)
    # Late import to avoid circular import
    import salt.utils.data
    return ''.join(
        difflib.unified_diff(
            salt.utils.data.decode_list(a, encoding=encoding),
            salt.utils.data.decode_list(b, encoding=encoding),
            *args, **kwargs
        )
    )
1173033
function(current, next, exclude){
   var di = diff(current, next);
   var diffs = di ? di.map(function(i){
      var str = JSON.stringify(i).replace("\"__data\",", "");
      return JSON.parse(str);
   }).filter(function(i){
      return i.path.join(",").indexOf("_") === -1;
   }).filter(function(i){
      return exclude.every(function(x){return i.path.indexOf(x) === -1; });
   }) : [];
   if(diffs.length > 0){
      return diffs;
   }
   else{
      return null;
   }
}
187369
def _get_diffs(cls, dict1, dict2, ignore_missing_keys):
        '''
        
        '''
        ret_dict = {}
        for p in dict1.keys():
            if p not in dict2:
                ret_dict.update({p: {'new': dict1[p], 'old': cls.NONE_VALUE}})
            elif dict1[p] != dict2[p]:
                if isinstance(dict1[p], dict) and isinstance(dict2[p], dict):
                    sub_diff_dict = cls._get_diffs(dict1[p], dict2[p],
                                                   ignore_missing_keys)
                    if sub_diff_dict:
                        ret_dict.update({p: sub_diff_dict})
                else:
                    ret_dict.update({p: {'new': dict1[p], 'old': dict2[p]}})
        if not ignore_missing_keys:
            for p in dict2.keys():
                if p not in dict1.keys():
                    ret_dict.update({p: {'new': cls.NONE_VALUE,
                                         'old': dict2[p]}})
        return ret_dict
219252
def _create_diff(diff, fun, key, prev, curr):

    '''
    
    '''

    if not fun(prev):
        _create_diff_action(diff, 'added', key, curr)
    elif fun(prev) and not fun(curr):
        _create_diff_action(diff, 'removed', key, prev)
    elif not fun(curr):
        _create_diff_action(diff, 'updated', key, curr)
1363111
def _compute_diff(map1, map2):
        
        data = map1.data - map2.data
        return HpxMap(data, map1.hpx)
1292450
def diffs(options = {})
      if parents.empty?
        show
      else
        self.class.diff(@repo, parents.first.id, @id, [], options)
      end
    end
601268
def diff(self, other, **kwargs):
        
        return JsonDiff(
            base_type_name=type(self).__name__,
            other_type_name=type(other).__name__,
            values=self.diff_iter(other, **kwargs),
        )
715070
def diff(self, items):
        
        return self.__class__([i for i in self.items if i not in items])
763118
def idfdiffs(idf1, idf2):
    """"""
    # for any object type, it is sorted by name
    thediffs = {}
    keys = idf1.model.dtls # undocumented variable

    for akey in keys:
        idfobjs1 = idf1.idfobjects[akey]
        idfobjs2 = idf2.idfobjects[akey]
        names = set([getobjname(i) for i in idfobjs1] +
                    [getobjname(i) for i in idfobjs2])
        names = sorted(names)
        idfobjs1 = sorted(idfobjs1, key=lambda idfobj: idfobj['obj'])
        idfobjs2 = sorted(idfobjs2, key=lambda idfobj: idfobj['obj'])
        for name in names:
            n_idfobjs1 = [item for item in idfobjs1
                          if getobjname(item) == name]
            n_idfobjs2 = [item for item in idfobjs2
                          if getobjname(item) == name]
            for idfobj1, idfobj2 in zip_longest(n_idfobjs1,
                                                           n_idfobjs2):
                if idfobj1 == None:
                    thediffs[(idfobj2.key.upper(), 
                                getobjname(idfobj2))] = (None, idf2.idfname) #(idf1.idfname, None) -> old
                    break
                if idfobj2 == None:
                    thediffs[(idfobj1.key.upper(), 
                                getobjname(idfobj1))] = (idf1.idfname, None) # (None, idf2.idfname) -> old
                    break
                for i, (f1, f2) in enumerate(zip(idfobj1.obj, idfobj2.obj)):
                    if i == 0:
                        f1, f2 = f1.upper(), f2.upper()
                    if f1 != f2:
                        thediffs[(
                            akey,
                            getobjname(idfobj1),
                            idfobj1.objidd[i]['field'][0])] = (f1, f2)
    return thediffs