Welcome, guest | Sign In | My Account | Store | Cart
KEYNOTFOUND = '<KEYNOTFOUND>'       # KeyNotFound for dictDiff

def dict_diff(first, second):
   
""" Return a dict of keys that differ with another config object.  If a value is
        not found in one fo the configs, it will be represented by KEYNOTFOUND.
        @param first:   Fist dictionary to diff.
        @param second:  Second dicationary to diff.
        @return diff:   Dict of Key => (first.val, second.val)
    """

    diff
= {}
   
# Check all keys in first dict
   
for key in first.keys():
       
if (not second.has_key(key)):
            diff
[key] = (first[key], KEYNOTFOUND)
       
elif (first[key] != second[key]):
            diff
[key] = (first[key], second[key])
   
# Check all keys in second dict to find missing
   
for key in second.keys():
       
if (not first.has_key(key)):
            diff
[key] = (KEYNOTFOUND, second[key])
   
return diff

History