1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
|
from .core import StrategyList
class DictStrategies(StrategyList):
"""
Contains the strategies provided for dictionaries.
"""
NAME = "dict"
@staticmethod
def strategy_merge(config, path, base, nxt):
"""
for keys that do not exists,
use them directly. if the key exists
in both dictionaries, attempt a value merge.
"""
for k, v in nxt.items():
if k not in base:
base[k] = v
else:
base[k] = config.value_strategy(path + [k], base[k], v)
return base
@staticmethod
def strategy_override(config, path, base, nxt):
"""
move all keys in nxt into base, overriding
conflicts.
"""
return nxt
|