blob: ba94c1f97f1484a77e98a5f5e959ed0f263743ba [file] [log] [blame]
martin f. krafftf37f0682013-06-14 16:36:20 +02001#
2# -*- coding: utf-8 -*-
3#
4# This file is part of reclass (http://github.com/madduck/reclass)
5#
6# Copyright © 2007–13 martin f. krafft <madduck@madduck.net>
7# Released under the terms of the Artistic Licence 2.0
8#
9from base import BaseDictMerger
10
11class DictRecursiveUpdate(BaseDictMerger):
12
13 def merge(self, first, second):
14 ret = first.copy()
15 for k,v in second.iteritems():
16 if k in ret:
17 if isinstance(ret[k], dict):
18 if isinstance(v, (list, tuple)):
19 v = dict(v)
20 ret[k] = self.merge(ret[k], v)
21 else:
22 ret[k] = v
23 else:
24 ret[k] = v
25 return ret