Example #1
0
def diff(tree1, tree2):
    walked1 = dict(walk(tree1))
    walked2 = dict(walk(tree2))
    paths1 = set(walked1.iterkeys())
    paths2 = set(walked2.iterkeys())
    removed = paths1 - paths2
    added = paths2 - paths1
    changed = {path for path in paths1.intersection(paths2) if walked1[path] != walked2[path]}
    return added, removed, changed
Example #2
0
def _match_impl(tree, pattern):
    from _path import Path
    for path, _ in walk(tree):
        matched, matched_context = _match_pattern(pattern, path)
        if matched:
            matched_context['%'] = Path(tree, path)
            matched_context['$'] = pattern
            yield matched_context
Example #3
0
def structural_copy(tree):
    result = Tree()
    r = Path(result)
    for path, leaf in walk(tree):
        set_at(r, path, leaf)
    return result