def __call__(self, form, field): if not is_valid_uri( field.data, require_authority=self.require_authority, allowed_schemes=self.allowed_schemes, require_scheme=self.require_scheme, ): raise ValidationError("Invalid URI")
def _validate_project_url(value): try: label, url = value.split(", ", 1) except ValueError: raise wtforms.validators.ValidationError( "Use both a label and an URL.") from None if not label: raise wtforms.validators.ValidationError("Use a label.") if len(label) > 32: raise wtforms.validators.ValidationError("Use 32 characters or less.") if not url: raise wtforms.validators.ValidationError("Use an URL.") if not http.is_valid_uri(url, require_authority=False): raise wtforms.validators.ValidationError("Use valid URL.")
def _validate_project_url(value): try: label, url = value.split(", ", 1) except ValueError: raise wtforms.validators.ValidationError( "Must have both a label and an URL.", ) from None if not label: raise wtforms.validators.ValidationError("Must have a label.") if len(label) > 32: raise wtforms.validators.ValidationError( "Label must not be longer than 32 characters.") if not url: raise wtforms.validators.ValidationError("Must have an URL.") if not http.is_valid_uri(url, require_authority=False): raise wtforms.validators.ValidationError("Invalid URL.")
def _validate_project_url(value): try: label, url = value.split(", ", 1) except ValueError: raise wtforms.validators.ValidationError( "Use both a label and an URL." ) from None if not label: raise wtforms.validators.ValidationError("Use a label.") if len(label) > 32: raise wtforms.validators.ValidationError("Use 32 characters or less.") if not url: raise wtforms.validators.ValidationError("Use an URL.") if not http.is_valid_uri(url, require_authority=False): raise wtforms.validators.ValidationError("Use valid URL.")
def _validate_project_url(value): try: label, url = value.split(", ", 1) except ValueError: raise wtforms.validators.ValidationError( "Must have both a label and an URL.", ) from None if not label: raise wtforms.validators.ValidationError("Must have a label.") if len(label) > 32: raise wtforms.validators.ValidationError( "Label must not be longer than 32 characters." ) if not url: raise wtforms.validators.ValidationError("Must have an URL.") if not http.is_valid_uri(url, require_authority=False): raise wtforms.validators.ValidationError("Invalid URL.")
def test_invalid(self, uri): assert not is_valid_uri(uri)
def test_valid(self, uri): assert is_valid_uri(uri)
def contains_valid_uris(items): """Returns boolean representing whether the input list contains any valid URIs """ return any(is_valid_uri(i) for i in items)
def test_authority_not_required(self): assert is_valid_uri("http://", require_authority=False)
def test_scheme_not_required(self): assert is_valid_uri("//example.com", require_scheme=False)
def test_plain_schemes(self): assert is_valid_uri("ftp://example.com/", require_scheme=True, allowed_schemes=[])