def METHOD_NAME(node, tag, attr=None, val=None):
    if isinstance(node, tuple):
        node = node[2]
    if not isinstance(node, list):
        raise ValueError("child not found")
    for child in node:
        if match(child, tag, attr, val):
            return child
    raise ValueError("child not found")