Browse Source

[3373] Addressed review comments.

The merge logic was simplified a bit and the commentary was improved.
Thomas Markwalder 11 years ago
parent
commit
688e0b4693
1 changed files with 9 additions and 11 deletions
  1. 9 11
      src/lib/python/isc/cc/data.py

+ 9 - 11
src/lib/python/isc/cc/data.py

@@ -1,4 +1,4 @@
-# Copyright (C) 2010  Internet Systems Consortium.
+# Copyright (C) 2010-2014  Internet Systems Consortium.
 #
 # Permission to use, copy, modify, and distribute this software for any
 # purpose with or without fee is hereby granted, provided that the above
@@ -51,20 +51,18 @@ def remove_identical(a, b):
         del(a[id])
 
 def merge(orig, new):
-    """Merges the contents of new into orig. If the element is dict
-       orig and then it goes recursive to merge the maps.
-       If an element value is None in new it will be removed in orig.
-       Previously this method was relying on dict.update but this does
-       not do deep merges in the manner required."""
+    """Merges the contents of one dictionary into another.
+       The merge is done element by element, in order to recursivley merge
+       any elements which are themselves dictionaries. If an element value
+       is None in new it will be removed in orig. Previously this method
+       relied on dict.update but this does not do deep merges properly.
+       Raises a DataTypeError is either argument is not a dict"""
     if type(orig) != dict or type(new) != dict:
         raise DataTypeError("Not a dict in merge()")
 
     for key in new.keys():
-        if (key in orig):
-            if (type(orig[key]) == dict):
-                merge(orig[key], new[key])
-            else:
-                orig[key] = new[key]
+        if ((key in orig) and (type(orig[key]) == dict)):
+            merge(orig[key], new[key])
         else:
             orig[key] = new[key]