Did I find the right examples for you? yes no      Crawl my project      Python Jobs

All Samples(9)  |  Call(8)  |  Derive(0)  |  Import(1)

        def update_config(conf, overwrites):
    wildcard_keys = []
    for k, v in overwrites.iteritems():
        if k == '__all__':
            continue
        if  k.startswith('___') or k.endswith('___'):
            wildcard_keys.append(k)
            continue

        if k.endswith('__extend__'):
            k = k[:-len('__extend__')]
            if k not in conf:
                conf[k] = v
            elif isinstance(v, list):
                conf[k].extend(v)
            else:
                raise ValueError('cannot extend non-list:', v)
        elif k not in conf:
            conf[k] = copy(v)
        else:
            if isinstance(conf[k], dict) and isinstance(v, dict):
                conf[k] = update_config(conf[k], v)
            else:
                conf[k] = copy(v)

    if '__all__' in overwrites:
        v = overwrites['__all__']
        for conf_k, conf_v in conf.iteritems():
            if isinstance(conf_v, dict):
                conf[conf_k] = update_config(conf_v, v)
            else:
                conf[conf_k] = v

    if wildcard_keys:
        for key in wildcard_keys:
            v = overwrites[key]
            if key.startswith('___'):
                key = key[3:]
                key_check = lambda x: x.endswith(key)
            else:
                key = key[:-3]
                key_check = lambda x: x.startswith(key)
            for conf_k, conf_v in conf.iteritems():
                if not key_check(conf_k):
                    continue
                if isinstance(conf_v, dict):
                    conf[conf_k] = update_config(conf_v, v)
                else:
                    conf[conf_k] = v

    return conf
        


src/m/a/mapproxy-HEAD/mapproxy/test/unit/test_util_conf_utils.py   mapproxy(Download)
# limitations under the License.
 
from mapproxy.script.conf.utils import update_config
 
from copy import deepcopy
    def test_empty(self):
        a = {'a': 'foo', 'b': 42}
        b = {}
        eq_(update_config(deepcopy(a), b), a)
 
    def test_add(self):
        a = {'a': 'foo', 'b': 42}
        b = {'c': [1, 2, 3]}
        eq_(update_config(a, b),
    def test_mod(self):
        a = {'a': 'foo', 'b': 42, 'c': {}}
        b = {'a': [1, 2, 3], 'c': 1}
        eq_(update_config(a, b),
            {'b': 42, 'a': [1, 2, 3], 'c': 1})
 
    def test_nested_add_mod(self):
        a = {'a': 'foo', 'b': {'ba': 42, 'bb': {}}}
        b = {'b': {'bb': {'bba': 1}, 'bc': [1, 2, 3]}}
        eq_(update_config(a, b),