Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def url(url, require_scheme=True):
"""Raises an error if the url doesn't look like a URL."""
try:
if not rfc3986.is_valid_uri(url, require_scheme=require_scheme):
raise exceptions.InvalidURL(url=url)
p_url = rfc3986.urlparse(rfc3986.normalize_uri(url))
if require_scheme:
if p_url.scheme != 'http' and p_url.scheme != 'https':
raise exceptions.InvalidURL(url=url)
except Exception:
raise exceptions.InvalidURL(url=url)
return True
def _validate_uri(instance):
return rfc3986.is_valid_uri(instance, require_scheme=True,
require_authority=True)
def cast_uri(self, value):
if not self._type_check(value):
return False
if is_valid_uri(value, require_scheme=True):
return value
else:
raise exceptions.InvalidURI('{0} is not a valid uri'.format(value))
def _validate_uri(instance):
return rfc3986.is_valid_uri(instance, require_scheme=True,
require_authority=True)