How to use the dpath.util.merge function in dpath

To help you get started, we’ve selected a few dpath examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github akesterson / dpath-python / tests / test_util_merge.py View on Github external
def test_merge_simple_dict():
    src = {
        "dict": {
            "key": "WEHAW"
            }
        }
    dst = {
        "dict": {
            "key": ""
            }
        }
    dpath.util.merge(dst, src)
    nose.tools.eq_(dst["dict"]["key"], src["dict"]["key"])
github akesterson / dpath-python / tests / test_types.py View on Github external
def test_types_merge_simple_list_replace():
    src = TestMapping({
        "list": TestSequence([7, 8, 9, 10])
        })
    dst = TestMapping({
        "list": TestSequence([0, 1, 2, 3])
        })
    dpath.util.merge(dst, src, flags=dpath.util.MERGE_REPLACE)
    nose.tools.eq_(dst["list"], TestSequence([7, 8, 9, 10]))
github akesterson / dpath-python / tests / test_util_merge.py View on Github external
dst1 = {}
    for d in [copy.deepcopy(src), copy.deepcopy(p1)]:
        dpath.util.merge(dst1, d)
    dst2 = {}
    for d in [copy.deepcopy(src), copy.deepcopy(p2)]:
        dpath.util.merge(dst2, d)
    assert dst1["l"] == [1, 2]
    assert dst2["l"] == [1]
    
    dst1 = {}
    for d in [src, p1]:
        dpath.util.merge(dst1, d)
    dst2 = {}
    for d in [src, p2]:
        dpath.util.merge(dst2, d)
    assert dst1["l"] == [1, 2]
    assert dst2["l"] == [1, 2]
github akesterson / dpath-python / tests / test_util_merge.py View on Github external
def test_merge_simple_string():
    src = {
        "string": "lol I am a string"
        }
    dst = {
        "string": "lol I am a string"
        }
    dpath.util.merge(dst, src)
    nose.tools.eq_(dst["string"], src["string"])
github robotcaresystems / RoboticsLanguage / RoboticsLanguage / Transformers / TemporalLogic / Transform.py View on Github external
# interval operator
    if len(logic.getchildren()) > 1:
      logic_type += 'Interval'

    # fill information about logic operator
    logic_name = logic_type + '_' + str(logic_id_counter) + '_'
    logic.attrib['temporalLogicId'] = str(logic_id_counter)
    logic.attrib['temporalLogicName'] = logic_name
    logic.attrib['temporalLogicVariables'] = ','.join(all_variables)

    # add logic update function to all variable involved in this operator
    for variable in all_variables:
      new_parameters = {}
      dpath.util.new(new_parameters, '/Transformers/Base/variables/' + variable + '/operators/assign/post/Cpp',
                     ['logic' + logic_type[0].title() + logic_type[1:] + str(logic_id_counter) + '()'])
      dpath.util.merge(parameters, new_parameters)

    # create text element for the GUI
    if 'HTMLGUI' in parameters['globals']['output']:

      # make a copy of the code to not polute it with extra attributes
      xml_copy = copy.deepcopy(logic)
      root = etree.Element("root")
      root.append(xml_copy)

      # use the RoL serialiser to create the text tag
      Serialise.serialise(root.getchildren()[0], parameters, parameters['language'], 'RoL')

      # annotate tag
      logic.attrib['temporalLogicText'] = root.getchildren()[0].attrib['RoL']

  return logic_id_counter
github Tencent / bk-bcs-saas / bcs-app / backend / bcs_k8s / app / utils.py View on Github external
def merge_valuefile(source, new):
    source = ruamel_yaml_load(source)
    if not source:
        source = ordereddict()

    new = ruamel_yaml_load(new)
    dpath.util.merge(source, new)
    return ruamel_yaml_dump(source)
github naorlivne / parse_it / parse_it / envvars / envvars.py View on Github external
def split_envvar_combained_dict(divider: str = "_", force_uppercase: bool = True):
    """Returns a dict of all envvars that has had their keys split by the divider into nested dicts

                    Arguments:
                        divider -- the string letter by which to divide the envvar key by, defaults to "_"
                        force_uppercase -- if the envvar key will be forced to be all in UPPERCASE, defaults to True
                    Returns:
                        envvar_split_dict -- A dict that is the result of all envvars being split by the divider with
                            the value appended as the bottom most of the nest key
    """
    envvar_dict = read_all_envvars_to_dict(force_uppercase=force_uppercase)
    envvar_split_dict = {}
    for envvar_key, envvar_value in envvar_dict.items():
        temp_split_envvar = split_envvar(envvar_key, str(envvar_value), divider=divider,
                                         force_uppercase=force_uppercase)
        dpath.util.merge(envvar_split_dict, temp_split_envvar)
    return envvar_split_dict