def FqdnUrl(v): """Verify that the value is a Fully qualified domain name URL. >>> s = Schema(FqdnUrl()) >>> with raises(MultipleInvalid, 'expected a Fully qualified domain name URL'): ... s("http://localhost/") >>> s('http://w3.org') 'http://w3.org' """ try: parsed_url = _url_validation(v) if "." not in parsed_url.netloc: raise UrlInvalid("must have a domain name in URL") return v except: raise ValueError
def UrlPath(v): """Verify that the value is a relative URL. >>> s = Schema(Url()) >>> with raises(MultipleInvalid, 'expected a URL'): ... s(1) >>> s('http://w3.org') 'http://w3.org' """ try: parsed = urlparse.urlparse(v) if not parsed.path or parsed.netloc or parsed.scheme: raise UrlInvalid("must have only a URL path") return parsed except Exception: raise ValueError
def _url_validation(v): parsed = urlparse.urlparse(v) if not parsed.scheme or not parsed.netloc: raise UrlInvalid("must have a URL scheme and host") return parsed
def _uri(s: str) -> str: parsed = urllib.parse.urlparse(s) if parsed.scheme not in ["http", "https"] or not parsed.netloc: raise UrlInvalid("URL is invalid") return s