[svn] commit: r3378 - /branches/trac22/src/lib/python/isc/cc/data.py

BIND 10 source code commits bind10-changes at lists.isc.org
Wed Oct 27 15:15:52 UTC 2010


Author: jelte
Date: Wed Oct 27 15:15:52 2010
New Revision: 3378

Log:
modified merge()

Modified:
    branches/trac22/src/lib/python/isc/cc/data.py

Modified: branches/trac22/src/lib/python/isc/cc/data.py
==============================================================================
--- branches/trac22/src/lib/python/isc/cc/data.py (original)
+++ branches/trac22/src/lib/python/isc/cc/data.py Wed Oct 27 15:15:52 2010
@@ -41,17 +41,20 @@
        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"""




More information about the bind10-changes mailing list