def _validate_timeout(timeout, infinity_ok=False):
    """
    Raises an exception if the given timeout is an invalid value.
    """
    if timeout is None:
        return

    if timeout == 'infinity':
        if infinity_ok:
            return
        else:
            raise ValueError(
                'timeout must be a positive integer '
                '("infinity" is not valid)')

    if isinstance(timeout, six.integer_types) and timeout > 0:
        return

    raise ValueError('timeout must be a positive integer')
Raises an exception if the given timeout is an invalid value.