Ejemplo n.º 1
0
def compare_trees(tree1, tree2):
    """Generates an xmldiff from two lxml trees."""
    opts = {'ratio_mode': 'accurate', 'F': 0.8}
    formatter = formatting.DiffFormatter(normalize=formatting.WS_BOTH,
                                         pretty_print=True)
    diff = diff_trees(tree1, tree2, diff_options=opts, formatter=formatter)

    return patch.DiffParser().parse(diff)
Ejemplo n.º 2
0
def patch_file(actions, tree):
    """Takes two filenames or streams, one with XML the other a diff"""
    tree = etree.parse(tree)

    if isinstance(actions, six.string_types):
        # It's a string, so it's a filename
        with open(actions) as f:
            actions = f.read()
    else:
        # We assume it's a stream
        actions = actions.read()

    actions = patch.DiffParser().parse(actions)
    tree = patch_tree(actions, tree)
    return etree.tounicode(tree)
Ejemplo n.º 3
0
def patch_text(actions, tree):
    """Takes a string with XML and a string with actions"""
    tree = etree.fromstring(tree)
    actions = patch.DiffParser().parse(actions)
    tree = patch_tree(actions, tree)
    return etree.tounicode(tree)