Return a dict representing the differences between the dicts `old` and
    `new`. Deleted keys appear as a key with the value :data:`None`, added and
    changed keys appear as a key with the new value.
553864
def dict_diff(old, new):
    
    old_keys = viewkeys(old)
    new_keys = viewkeys(dict(new))
    out = {}
    for key in new_keys - old_keys:
        out[key] = new[key]
    for key in old_keys - new_keys:
        out[key] = None
    for key in old_keys & new_keys:
        if old[key] != new[key]:
            out[key] = new[key]
    return out
1006492
def dict_update_newkeys(dict_, dict2):
    
    for key, val in six.iteritems(dict2):
        if key not in dict_:
            dict_[key] = val
874867
def diff_dict(dict1, dict2, ignore_missing=False):
    """"""
    unidict1 = dict_unicodeize(dict1)
    unidict2 = dict_unicodeize(dict2)
    if ((not ignore_missing) and (len(unidict1) != len(unidict2))) or \
       (ignore_missing and (len(unidict1) >= len(unidict2))):
        return True

    for comp_k, comp_v in iteritems(unidict1):
        if comp_k not in unidict2:
            return True
        else:
            if comp_v != unidict2[comp_k]:
                return True

    return False
557470
def changes(self):
        
        try:
            return self.added, self.removed
        finally:
            self.added = list()
            self.removed = list()
71043
def changes_str(self):
        ''''''
        changes = ''
        for item in self._get_recursive_difference(type='intersect'):
            if item.diffs:
                changes = ''.join([changes,
                                   # Tabulate comment deeper, show the key attribute and the value
                                   # Next line should be tabulated even deeper,
                                   #  every change should be tabulated 1 deeper
                                   '\tidentified by {0} {1}:\n\t{2}\n'.format(
                                       self._key,
                                       item.past_dict[self._key],
                                       item.changes_str.replace('\n', '\n\t'))])
        for item in self._get_recursive_difference(type='removed'):
            if item.past_dict:
                changes = ''.join([changes,
                                   # Tabulate comment deeper, show the key attribute and the value
                                   '\tidentified by {0} {1}:'
                                   '\n\twill be removed\n'.format(self._key,
                                                                  item.past_dict[self._key])])
        for item in self._get_recursive_difference(type='added'):
            if item.current_dict:
                changes = ''.join([changes,
                                   # Tabulate comment deeper, show the key attribute and the value
                                   '\tidentified by {0} {1}:'
                                   '\n\twill be added\n'.format(self._key,
                                                                item.current_dict[self._key])])
        return changes
773817
def removed(self):
        '''
        
        '''
        def _removed(diffs, prefix):
            keys = []
            for key in diffs.keys():
                if isinstance(diffs[key], dict) and 'old' not in diffs[key]:
                    keys.extend(_removed(diffs[key],
                                       prefix='{0}{1}.'.format(prefix, key)))
                elif diffs[key]['new'] == self.NONE_VALUE:
                    keys.append('{0}{1}'.format(prefix, key))
                elif isinstance(diffs[key]['new'], dict):
                    keys.extend(
                        _removed(diffs[key]['new'],
                                 prefix='{0}{1}.'.format(prefix, key)))
            return keys

        return sorted(_removed(self._diffs, prefix=''))
462585
def dict(self):
        
        d = {p.key: getattr(self, p.key) for p in self.__mapper__.attrs
             if p.key not in ('contents', 'dataset')}

        d['modified_datetime'] = self.modified_datetime
        d['modified_ago'] = self.modified_ago

        return d
706654
def _get_instance_changes(current, state):
    '''
    
    '''
    # get keys
    current_keys = set(current.keys())
    state_keys = set(state.keys())

    # compare configs
    changed = salt.utils.data.compare_dicts(current, state)
    for change in salt.utils.data.compare_dicts(current, state):
        if change in changed and changed[change]['old'] == "":
            del changed[change]
        if change in changed and changed[change]['new'] == "":
            del changed[change]

    return changed
597356
def _tracked_model_diff(self):
        
        initial_state = self._tracked_model_initial_state
        current_state = serializer.dump_model(self)
        if current_state == initial_state:
            return None

        change_log = {}
        for field in initial_state:
            old_value = initial_state[field][Field.VALUE]
            new_value = current_state[field][Field.VALUE]
            if old_value == new_value:
                continue
            field_data = initial_state.copy()[field]
            del field_data[Field.VALUE]
            field_data[Field.OLD] = old_value
            field_data[Field.NEW] = new_value
            change_log[field] = field_data

        return change_log or None
1071637
def get_diff(self, ignore=[]):
        
        # ignore this and the caller frame
        ignore.append(inspect.currentframe()) #PYCHOK change ignore
        self.o1 = self._get_objects(ignore)
        diff = muppy.get_diff(self.o0, self.o1)
        self.o0 = self.o1
        # manual cleanup, see comment above
        del ignore[:] #PYCHOK change ignore
        return diff
286788
def deleted_keys(self) -> Iterable[bytes]:
        
        for key, value in self._changes.items():
            if value is DELETED:
                yield key
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
1370407
def _get_values(cls, diff_dict, type='new'):
        '''
        
        '''
        ret_dict = {}
        for p in diff_dict.keys():
            if type in diff_dict[p].keys():
                ret_dict.update({p: diff_dict[p][type]})
            else:
                ret_dict.update(
                    {p: cls._get_values(diff_dict[p], type=type)})
        return ret_dict
98302
def compare_lists(old=None, new=None):
    '''
    
    '''
    ret = dict()
    for item in new:
        if item not in old:
            ret['new'] = item
    for item in old:
        if item not in new:
            ret['old'] = item
    return ret
1074754
def difference(self, *iterables):
        
        diff = self._set.difference(*iterables)
        return self._fromset(diff, key=self._key)
763621
def compare_dict(da, db):
    
    sa = set(da.items())
    sb = set(db.items())
    
    diff = sa & sb
    return dict(sa - diff), dict(sb - diff)
343826
def values(self):
        
        report = {}
        for k, k_changes in self._changes.items():
            if len(k_changes) == 1:
                report[k] = k_changes[0].new_value
            elif k_changes[0].old_value != k_changes[-1].new_value:
                report[k] = k_changes[-1].new_value
        return report