Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Adam Osuchowski
Kea
Commits
688e0b46
Commit
688e0b46
authored
Mar 11, 2014
by
Thomas Markwalder
Browse files
[3373] Addressed review comments.
The merge logic was simplified a bit and the commentary was improved.
parent
bf76c3bd
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/lib/python/isc/cc/data.py
View file @
688e0b46
# 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
]
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment