Commit 688e0b46 authored by Thomas Markwalder's avatar Thomas Markwalder
Browse files

[3373] Addressed review comments.

The merge logic was simplified a bit and the commentary was improved.
parent bf76c3bd
# 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]
......
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