Return a wrapper that runs given method only for valid hosts.

    :param func: a method to be wrapped
    :returns: a wrapper that adds argument validation

def accepts_valid_host(func):
    """Return a wrapper that runs given method only for valid hosts.

    :param func: a method to be wrapped
    :returns: a wrapper that adds argument validation
    """
    @functools.wraps(func)
    def wrapper(obj, value, *args, **kwargs):
        """Run the function and return a value for a valid host.

        :param obj: an object in whose class the func is defined
        :param value: a value expected to be a valid host string
        :returns: a return value of the function func
        :raises InvalidHostError: if the value is not valid
        """
        if not is_valid_host(value):
            raise InvalidHostError
        return func(obj, value, *args, **kwargs)
    return wrapper