dpath/util.py
def merge(dst, src, separator="/", afilter=None, flags=MERGE_ADDITIVE, _path=""):
    """Merge source into destination. Like dict.update() but performs
    deep merging.

    flags is an OR'ed combination of MERGE_ADDITIVE, MERGE_REPLACE, or
    MERGE_TYPESAFE.
        * MERGE_ADDITIVE : List objects are combined onto one long
          list (NOT a set). This is the default flag.
        * MERGE_REPLACE : Instead of combining list objects, when
          2 list objects are at an equal depth of merge, replace
          the destination with the source.
        * MERGE_TYPESAFE : When 2 keys at equal levels are of different
          types, raise a TypeError exception. By default, the source
          replaces the destination in this situation.
    """

    if afilter:
        # Having merge do its own afiltering is dumb, let search do the
        # heavy lifting for us.
        src = search(src, '**', afilter=afilter)
        return merge(dst, src)

    def _check_typesafe(obj1, obj2, key, path):
        if not key in obj1:
            return
        elif ( (flags & MERGE_TYPESAFE == MERGE_TYPESAFE) and (type(obj1[key]) != type(obj2[key]))):
            raise TypeError("Cannot merge objects of type {} and {} at {}"
                            "".format(type(obj1[key]), type(obj2[key]), path))
        elif ( (flags & MERGE_TYPESAFE != MERGE_TYPESAFE) and (type(obj1[key]) != type(obj2[key]))):
            obj1.pop(key)

    if isinstance(src, dict):
        for (i, v) in enumerate(src):
            _check_typesafe(dst, src, v, separator.join([_path, str(v)]))

            if not v in dst:
                dst[v] = src[v]
            else:
                if not isinstance(src[v], (dict, list)):
                    dst[v] = src[v]
                else:
                    merge(dst[v], src[v], afilter=afilter, flags=flags,
                          _path=separator.join([_path, str(v)]), separator=separator)
    elif isinstance(src, list):
        for (i, v) in enumerate(src):
            _check_typesafe(dst, src, i, separator.join([_path, str(i)]))
            dsti = i
            if ( flags & MERGE_ADDITIVE):
                dsti = len(dst)
            if dsti >= len(dst):
                dst += [None] * (dsti - (len(dst) - 1))
            if dst[dsti] == None:
                dst[dsti] = src[i]
            else:
                if not isinstance(src[i], (dict, list)):
                    dst[dsti] = src[i]
                else:
                    merge(dst[i], src[i], afilter=afilter, flags=flags,
                          _path=separator.join([_path, str(i)]), separator=separator)
Merge source into destination. Like dict.update() but performs
    deep merging.

    flags is an OR'ed combination of MERGE_ADDITIVE, MERGE_REPLACE, or
    MERGE_TYPESAFE.
        * MERGE_ADDITIVE : List objects are combined onto one long
          list (NOT a set). This is the default flag.
        * MERGE_REPLACE : Instead of combining list objects, when
          2 list objects are at an equal depth of merge, replace
          the destination with the source.
        * MERGE_TYPESAFE : When 2 keys at equal levels are of different
          types, raise a TypeError exception. By default, the source
          replaces the destination in this situation.
    
Merge source into destination. Like dict.update() but performs
deep merging.

flags is an OR'ed combination of MERGE_ADDITIVE, MERGE_REPLACE, or
MERGE_TYPESAFE.
MERGE_ADDITIVE : List objects are combined onto one long
list (NOT a set). This is the default flag.
MERGE_REPLACE : Instead of combining list objects, when
2 list objects are at an equal depth of merge, replace
the destination with the source.
MERGE_TYPESAFE : When 2 keys at equal levels are of different
types, raise a TypeError exception. By default, the source
replaces the destination in this situation.
Merge source into destination . Like dict . update () but performs deep merging . flags is an OR ' ed combination of MERGE_ADDITIVE MERGE_REPLACE or MERGE_TYPESAFE . MERGE_ADDITIVE : List objects are combined onto one long list ( NOT a set ) . This is the default flag . MERGE_REPLACE : Instead of combining list objects when 2 list objects are at an equal depth of merge replace the destination with the source . MERGE_TYPESAFE : When 2 keys at equal levels are of different types raise a TypeError exception . By default the source replaces the destination in this situation .
def merge(dst, src, separator="/", afilter=None, flags=MERGE_ADDITIVE, _path=""):
    if afilter:
        src = search(src, '**', afilter=afilter)
        return merge(dst, src)
    def _check_typesafe(obj1, obj2, key, path):
        if not key in obj1:
            return
        elif ( (flags & MERGE_TYPESAFE == MERGE_TYPESAFE) and (type(obj1[key]) != type(obj2[key]))):
            raise TypeError("Cannot merge objects of type {} and {} at {}"
                            "".format(type(obj1[key]), type(obj2[key]), path))
        elif ( (flags & MERGE_TYPESAFE != MERGE_TYPESAFE) and (type(obj1[key]) != type(obj2[key]))):
            obj1.pop(key)
    if isinstance(src, dict):
        for (i, v) in enumerate(src):
            _check_typesafe(dst, src, v, separator.join([_path, str(v)]))
            if not v in dst:
                dst[v] = src[v]
            else:
                if not isinstance(src[v], (dict, list)):
                    dst[v] = src[v]
                else:
                    merge(dst[v], src[v], afilter=afilter, flags=flags,
                          _path=separator.join([_path, str(v)]), separator=separator)
    elif isinstance(src, list):
        for (i, v) in enumerate(src):
            _check_typesafe(dst, src, i, separator.join([_path, str(i)]))
            dsti = i
            if ( flags & MERGE_ADDITIVE):
                dsti = len(dst)
            if dsti >= len(dst):
                dst += [None] * (dsti - (len(dst) - 1))
            if dst[dsti] == None:
                dst[dsti] = src[i]
            else:
                if not isinstance(src[i], (dict, list)):
                    dst[dsti] = src[i]
                else:
                    merge(dst[i], src[i], afilter=afilter, flags=flags,
                          _path=separator.join([_path, str(i)]), separator=separator)
def merge ( dst , src , separator = "/" , afilter = None , flags = MERGE_ADDITIVE , _path = "" ) : if afilter : src = search ( src , '**' , afilter = afilter ) return merge ( dst , src ) def _check_typesafe ( obj1 , obj2 , key , path ) : if not key in obj1 : return elif ( ( flags & MERGE_TYPESAFE == MERGE_TYPESAFE ) and ( type ( obj1 [ key ] ) != type ( obj2 [ key ] ) ) ) : raise TypeError ( "Cannot merge objects of type {} and {} at {}" "" . format ( type ( obj1 [ key ] ) , type ( obj2 [ key ] ) , path ) ) elif ( ( flags & MERGE_TYPESAFE != MERGE_TYPESAFE ) and ( type ( obj1 [ key ] ) != type ( obj2 [ key ] ) ) ) : obj1 . pop ( key ) if isinstance ( src , dict ) : for ( i , v ) in enumerate ( src ) : _check_typesafe ( dst , src , v , separator . join ( [ _path , str ( v ) ] ) ) if not v in dst : dst [ v ] = src [ v ] else : if not isinstance ( src [ v ] , ( dict , list ) ) : dst [ v ] = src [ v ] else : merge ( dst [ v ] , src [ v ] , afilter = afilter , flags = flags , _path = separator . join ( [ _path , str ( v ) ] ) , separator = separator ) elif isinstance ( src , list ) : for ( i , v ) in enumerate ( src ) : _check_typesafe ( dst , src , i , separator . join ( [ _path , str ( i ) ] ) ) dsti = i if ( flags & MERGE_ADDITIVE ) : dsti = len ( dst ) if dsti >= len ( dst ) : dst += [ None ] * ( dsti - ( len ( dst ) - 1 ) ) if dst [ dsti ] == None : dst [ dsti ] = src [ i ] else : if not isinstance ( src [ i ] , ( dict , list ) ) : dst [ dsti ] = src [ i ] else : merge ( dst [ i ] , src [ i ] , afilter = afilter , flags = flags , _path = separator . join ( [ _path , str ( i ) ] ) , separator = separator )
Merge source into destination.
Merge source into destination .
"""Merge source into destination. Like dict.update() but performs
    deep merging.

    flags is an OR'ed combination of MERGE_ADDITIVE, MERGE_REPLACE, or
    MERGE_TYPESAFE.
        * MERGE_ADDITIVE : List objects are combined onto one long
          list (NOT a set). This is the default flag.
        * MERGE_REPLACE : Instead of combining list objects, when
          2 list objects are at an equal depth of merge, replace
          the destination with the source.
        * MERGE_TYPESAFE : When 2 keys at equal levels are of different
          types, raise a TypeError exception. By default, the source
          replaces the destination in this situation.
    """ # Having merge do its own afiltering is dumb, let search do the # heavy lifting for us.
dst
src
separator
afilter
flags
_path