labpack/compilers/json.py
def walk_data(target, source):

    ''' method to recursively walk parse tree and merge source into target '''

    from copy import deepcopy

    # skip if target and source are different datatypes
    if target.__class__.__name__ != source.__class__.__name__:
        pass
    # handle maps
    elif isinstance(target, dict):
        count = 0
        target = OrderedDict(target)
        for k, v in source.items():
            # insert fields not found in target
            if k not in target.keys():
                target[k] = v
                for i, key in enumerate(list(target.keys())):
                    if i >= count and key != k:
                        target.move_to_end(key)
            # else walk down maps and sequences
            elif isinstance(v, list) or isinstance(v, dict):
                target[k] = walk_data(target[k], v)
            count += 1
    # handle sequences
    elif isinstance(target, list):
        # walk down maps and sequences
        for i in range(len(target)):
            item = target[i]
            source_copy = deepcopy(source[0])
            if isinstance(item, dict) or isinstance(item, list):
                if source:
                    target[i] = walk_data(item, source_copy)

    return target
 method to recursively walk parse tree and merge source into target 
method to recursively walk parse tree and merge source into target
method to recursively walk parse tree and merge source into target
def walk_data(target, source):
    from copy import deepcopy
    if target.__class__.__name__ != source.__class__.__name__:
        pass
    elif isinstance(target, dict):
        count = 0
        target = OrderedDict(target)
        for k, v in source.items():
            if k not in target.keys():
                target[k] = v
                for i, key in enumerate(list(target.keys())):
                    if i >= count and key != k:
                        target.move_to_end(key)
            elif isinstance(v, list) or isinstance(v, dict):
                target[k] = walk_data(target[k], v)
            count += 1
    elif isinstance(target, list):
        for i in range(len(target)):
            item = target[i]
            source_copy = deepcopy(source[0])
            if isinstance(item, dict) or isinstance(item, list):
                if source:
                    target[i] = walk_data(item, source_copy)
    return target
def walk_data ( target , source ) : from copy import deepcopy if target . __class__ . __name__ != source . __class__ . __name__ : pass elif isinstance ( target , dict ) : count = 0 target = OrderedDict ( target ) for k , v in source . items ( ) : if k not in target . keys ( ) : target [ k ] = v for i , key in enumerate ( list ( target . keys ( ) ) ) : if i >= count and key != k : target . move_to_end ( key ) elif isinstance ( v , list ) or isinstance ( v , dict ) : target [ k ] = walk_data ( target [ k ] , v ) count += 1 elif isinstance ( target , list ) : for i in range ( len ( target ) ) : item = target [ i ] source_copy = deepcopy ( source [ 0 ] ) if isinstance ( item , dict ) or isinstance ( item , list ) : if source : target [ i ] = walk_data ( item , source_copy ) return target
method to recursively walk parse tree and merge source into target
method to recursively walk parse tree and merge source into target
''' method to recursively walk parse tree and merge source into target ''' # skip if target and source are different datatypes # handle maps # insert fields not found in target # else walk down maps and sequences # handle sequences # walk down maps and sequences
target
source