Commit dee43579 authored by Jelte Jansen's avatar Jelte Jansen

modified merge()


git-svn-id: svn://bind10.isc.org/svn/bind10/branches/trac22@3378 e5f2f494-b856-4b98-b285-d166d9295462
parent 3fe5cad0
......@@ -41,17 +41,20 @@ def merge(orig, new):
new it will be removed in orig."""
if type(orig) != dict or type(new) != dict:
raise DataTypeError("Not a dict in merge()")
for kn in new.keys():
if kn in orig:
if new[kn]:
if type(new[kn]) == dict:
merge(orig[kn], new[kn])
else:
orig[kn] = new[kn]
else:
del orig[kn]
else:
orig[kn] = new[kn]
orig.update(new)
remove_null_items(orig)
def remove_null_items(d):
"""Recursively removes all (key,value) pairs from d where the
value is None"""
null_keys = []
for key in d.keys():
if type(d[key]) == dict:
remove_null_items(d[key])
elif d[key] is None:
null_keys.append(key)
for k in null_keys:
del d[k]
def find(element, identifier):
"""Returns the subelement in the given data element, raises DataNotFoundError if not found"""
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment