def _get_parent_node_by_pred(node, pred, search_current=False):
    """Find the first parent node that satisfies a predicate function."""
    if not search_current:
        node = node.parent
    while node is not None:
        if pred(node):
            return node
        node = node.parent
    return None