#
# -*- coding: utf-8 -*-
#
# This file is part of reclass (http://github.com/madduck/reclass)
#
# Copyright © 2007–13 martin f. krafft <madduck@madduck.net>
# Released under the terms of the Artistic Licence 2.0
#
from base import BaseDictMerger

class DictRecursiveUpdate(BaseDictMerger):

    def merge(self, first, second):
        ret = first.copy()
        for k,v in second.iteritems():
            if k in ret:
                if isinstance(ret[k], dict):
                    if isinstance(v, (list, tuple)):
                        v = dict(v)
                    ret[k] = self.merge(ret[k], v)
                else:
                    ret[k] = v
            else:
                ret[k] = v
        return ret
