labpack/parsing/comparison.py
def _compare_list(new_list, old_list, change_list=None, root=None):

    '''
        a method for recursively listing changes made to a list

    :param new_list: list with new value
    :param old_list: list with old values
    :param change_list: list of differences between old and new
    :param root: string with record of path to the root of the main object
    :return: list of differences between old and new
    '''

    from copy import deepcopy
    if len(old_list) > len(new_list):
        same_len = len(new_list)
        for i in reversed(range(len(new_list), len(old_list))):
            new_path = deepcopy(root)
            new_path.append(i)
            change_list.append({'action': 'REMOVE', 'value': None, 'path': new_path})
    elif len(new_list) > len(old_list):
        same_len = len(old_list)
        append_list = []
        path = deepcopy(root)
        for i in range(len(old_list), len(new_list)):
            append_list.append(new_list[i])
        change_list.append({'action': 'APPEND', 'value': append_list, 'path': path})
    else:
        same_len = len(new_list)
    for i in range(0, same_len):
        new_path = deepcopy(root)
        new_path.append(i)
        if new_list[i].__class__ != old_list[i].__class__:
            change_list.append({'action': 'UPDATE', 'value': new_list[i], 'path': new_path})
        elif isinstance(new_list[i], dict):
            _compare_dict(new_list[i], old_list[i], change_list, new_path)
        elif isinstance(new_list[i], list):
            _compare_list(new_list[i], old_list[i], change_list, new_path)
        elif isinstance(new_list[i], set):
            _compare_set(new_list[i], old_list[i], change_list, new_path)
        elif new_list[i] != old_list[i]:
            change_list.append({'action': 'UPDATE', 'value': new_list[i], 'path': new_path})
    return change_list

        a method for recursively listing changes made to a list

    :param new_list: list with new value
    :param old_list: list with old values
    :param change_list: list of differences between old and new
    :param root: string with record of path to the root of the main object
    :return: list of differences between old and new
    
a method for recursively listing changes made to a list
a method for recursively listing changes made to a list
def _compare_list(new_list, old_list, change_list=None, root=None):
    from copy import deepcopy
    if len(old_list) > len(new_list):
        same_len = len(new_list)
        for i in reversed(range(len(new_list), len(old_list))):
            new_path = deepcopy(root)
            new_path.append(i)
            change_list.append({'action': 'REMOVE', 'value': None, 'path': new_path})
    elif len(new_list) > len(old_list):
        same_len = len(old_list)
        append_list = []
        path = deepcopy(root)
        for i in range(len(old_list), len(new_list)):
            append_list.append(new_list[i])
        change_list.append({'action': 'APPEND', 'value': append_list, 'path': path})
    else:
        same_len = len(new_list)
    for i in range(0, same_len):
        new_path = deepcopy(root)
        new_path.append(i)
        if new_list[i].__class__ != old_list[i].__class__:
            change_list.append({'action': 'UPDATE', 'value': new_list[i], 'path': new_path})
        elif isinstance(new_list[i], dict):
            _compare_dict(new_list[i], old_list[i], change_list, new_path)
        elif isinstance(new_list[i], list):
            _compare_list(new_list[i], old_list[i], change_list, new_path)
        elif isinstance(new_list[i], set):
            _compare_set(new_list[i], old_list[i], change_list, new_path)
        elif new_list[i] != old_list[i]:
            change_list.append({'action': 'UPDATE', 'value': new_list[i], 'path': new_path})
    return change_list
def _compare_list ( new_list , old_list , change_list = None , root = None ) : from copy import deepcopy if len ( old_list ) > len ( new_list ) : same_len = len ( new_list ) for i in reversed ( range ( len ( new_list ) , len ( old_list ) ) ) : new_path = deepcopy ( root ) new_path . append ( i ) change_list . append ( { 'action' : 'REMOVE' , 'value' : None , 'path' : new_path } ) elif len ( new_list ) > len ( old_list ) : same_len = len ( old_list ) append_list = [ ] path = deepcopy ( root ) for i in range ( len ( old_list ) , len ( new_list ) ) : append_list . append ( new_list [ i ] ) change_list . append ( { 'action' : 'APPEND' , 'value' : append_list , 'path' : path } ) else : same_len = len ( new_list ) for i in range ( 0 , same_len ) : new_path = deepcopy ( root ) new_path . append ( i ) if new_list [ i ] . __class__ != old_list [ i ] . __class__ : change_list . append ( { 'action' : 'UPDATE' , 'value' : new_list [ i ] , 'path' : new_path } ) elif isinstance ( new_list [ i ] , dict ) : _compare_dict ( new_list [ i ] , old_list [ i ] , change_list , new_path ) elif isinstance ( new_list [ i ] , list ) : _compare_list ( new_list [ i ] , old_list [ i ] , change_list , new_path ) elif isinstance ( new_list [ i ] , set ) : _compare_set ( new_list [ i ] , old_list [ i ] , change_list , new_path ) elif new_list [ i ] != old_list [ i ] : change_list . append ( { 'action' : 'UPDATE' , 'value' : new_list [ i ] , 'path' : new_path } ) return change_list
a method for recursively listing changes made to a list
a method for recursively listing changes made to a list
'''
        a method for recursively listing changes made to a list

    :param new_list: list with new value
    :param old_list: list with old values
    :param change_list: list of differences between old and new
    :param root: string with record of path to the root of the main object
    :return: list of differences between old and new
    '''
list of differences between old and new
list of differences between old and new
new_list
list with new value
list with new value
old_list
list with old values
list with old values
change_list
list of differences between old and new
list of differences between old and new
root
string with record of path to the root of the main object
string with record of path to the root of the main object