(url)
Raises an exception if the supplied URL is considered invalid or unsafe

    raise PossibleSSRFAttempt if the url resolves to a non-public ip address
    raise CannotResolveHost if the url host does not resolve
    raise InvalidURL if `url` can't be parsed as a URL (i.e. if it doesn't even "look" like a URL)
Raises an exception if the supplied URL is considered invalid or unsafe
Raises an exception if the supplied URL is considered invalid or unsafe
def validate_user_input_url(url):
    """
    Raises an exception if the supplied URL is considered invalid or unsafe

    raise PossibleSSRFAttempt if the url resolves to a non-public ip address
    raise CannotResolveHost if the url host does not resolve
    raise InvalidURL if `url` can't be parsed as a URL (i.e. if it doesn't even "look" like a URL)
    """
    parsed_url = urlparse(url)
    hostname = parsed_url.hostname
    scheme = parsed_url.scheme
    if hostname is None:
        raise InvalidURL()
    if scheme not in ['http', 'https']:
        raise PossibleSSRFAttempt('scheme not http(s)')

    for ip_address in resolve_to_ips(hostname):
        sanitize_ip(ip_address)
def validate_user_input_url ( url ) : parsed_url = urlparse ( url ) hostname = parsed_url . hostname scheme = parsed_url . scheme if hostname is None : raise InvalidURL ( ) if scheme not in [ 'http' , 'https' ] : raise PossibleSSRFAttempt ( 'scheme not http(s)' ) for ip_address in resolve_to_ips ( hostname ) : sanitize_ip ( ip_address )