3
# Copyright (C) 2012 Yahoo! Inc.
5
# Author: Joshua Harlow <harlowja@yahoo-inc.com>
7
# This program is free software: you can redistribute it and/or modify
8
# it under the terms of the GNU General Public License version 3, as
9
# published by the Free Software Foundation.
11
# This program is distributed in the hope that it will be useful,
12
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
# GNU General Public License for more details.
16
# You should have received a copy of the GNU General Public License
17
# along with this program. If not, see <http://www.gnu.org/licenses/>.
21
def __init__(self, merger, opts):
23
self._overwrite = 'overwrite' in opts
25
# This merging algorithm will attempt to merge with
26
# another dictionary, on encountering any other type of object
27
# it will not merge with said object, but will instead return
30
# On encountering a dictionary, it will create a new dictionary
31
# composed of the original and the one to merge with, if 'overwrite'
32
# is enabled then keys that exist in the original will be overwritten
33
# by keys in the one to merge with (and associated values). Otherwise
34
# if not in overwrite mode the 2 conflicting keys themselves will
36
def _on_dict(self, value, merge_with):
37
if not isinstance(merge_with, (dict)):
40
for (k, v) in merge_with.items():
42
if not self._overwrite:
43
merged[k] = self._merger.merge(merged[k], v)