import six
from typing import Mapping


def update_dict(old_dict, new_dict):
    """Updates old dictionary with data from a new one with respect to existing values.

    :param old_dict:
    :param new_dict:
    :return: updated dict
    :rtype: dict
    """
    for key, val in six.iteritems(new_dict):
        if isinstance(val, Mapping):
            old_dict[key] = update_dict(old_dict.get(key, {}), val)
        else:
            old_dict[key] = new_dict[key]
    return old_dict