human
Complete this python program:
def criterion_as_pairs(expression, consider_as_foreign_keys=None, consider_as_referenced_keys=None, any_operator=False):
assistant
#Here is the Python program you requested.

    """traverse an expression and locate binary criterion pairs.
    """
    if (consider_as_foreign_keys and consider_as_referenced_keys):
        raise exc.ArgumentError("Can    only    specify    one    of    'consider_as_foreign_keys'    or    'consider_as_referenced_keys'")
    def col_is(a, b):
        return a.compare(b)
    def visit_binary(binary):
        if ((not any_operator) and (binary.operator is not operators.eq)):
            return
        if ((not isinstance(binary.left, ColumnElement)) or (not isinstance(binary.right, ColumnElement))):
            return
        if consider_as_foreign_keys:
            if ((binary.left in consider_as_foreign_keys) and (col_is(binary.right, binary.left) or (binary.right not in consider_as_foreign_keys))):
                pairs.append((binary.right, binary.left))
            elif ((binary.right in consider_as_foreign_keys) and (col_is(binary.left, binary.right) or (binary.left not in consider_as_foreign_keys))):
                pairs.append((binary.left, binary.right))
        elif consider_as_referenced_keys:
            if ((binary.left in consider_as_referenced_keys) and (col_is(binary.right, binary.left) or (binary.right not in consider_as_referenced_keys))):
                pairs.append((binary.left, binary.right))
            elif ((binary.right in consider_as_referenced_keys) and (col_is(binary.left, binary.right) or (binary.left not in consider_as_referenced_keys))):
                pairs.append((binary.right, binary.left))
        elif (isinstance(binary.left, Column) and isinstance(binary.right, Column)):
            if binary.left.references(binary.right):
                pairs.append((binary.right, binary.left))
            elif binary.right.references(binary.left):
                pairs.append((binary.left, binary.right))
    pairs = []
    visitors.traverse(expression, {}, {'binary': visit_binary})
    return pairs