|
@@ -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
|
|
# Permission to use, copy, modify, and distribute this software for any
|
|
# purpose with or without fee is hereby granted, provided that the above
|
|
# purpose with or without fee is hereby granted, provided that the above
|
|
@@ -51,20 +51,18 @@ def remove_identical(a, b):
|
|
del(a[id])
|
|
del(a[id])
|
|
|
|
|
|
def merge(orig, new):
|
|
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:
|
|
if type(orig) != dict or type(new) != dict:
|
|
raise DataTypeError("Not a dict in merge()")
|
|
raise DataTypeError("Not a dict in merge()")
|
|
|
|
|
|
for key in new.keys():
|
|
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:
|
|
else:
|
|
orig[key] = new[key]
|
|
orig[key] = new[key]
|
|
|
|
|