def valid_int(param, allow_zero=False, allow_negative=False):
    """Validate that param is an integer, raise an exception if not"""
    pt = param
    try:  # a very permissive integer typecheck
        pt += 1
    except TypeError:
        raise TypeError(
            "Expected integer but found argument of type '{}'".format(type(param)))
    if not allow_negative and param < 0:
        raise ValueError("Expected nonnegative number but got '{}'".format(param))
    if not allow_zero and param == 0:
        raise ValueError("Expected nonzero number but got '{}'".format(param))
    return param