Part of lp.app.validators
Function | valid_absolute_url | Validate an absolute URL. |
Function | valid_builder_url | validate a url for a builder. |
Function | builder_url_validator | Return True if the url is valid, or raise a LaunchpadValidationError |
Function | validate_url | Returns a boolean stating whether 'url' is a valid URL. |
Function | valid_webref | Returns True if web_ref is a valid download URL, or raises a |
Validate an absolute URL.
It looks like this function has been deprecated by lp.app.validators.validation.
We define this as something that can be parsed into a URL that has both a protocol and a network address.
>>> valid_absolute_url('sftp://chinstrap.ubuntu.com/foo/bar') True >>> valid_absolute_url('http://www.example.com') True >>> valid_absolute_url('whatever:/uxample.com/blah') False >>> valid_absolute_url('whatever://example.com/blah') True
Unicode urls are ascii encoded, and a failure here means it isn't valid.
>>> valid_absolute_url(u'http://www.example.com/test...') True >>> valid_absolute_url(u'http://www.example.com/test\u2026') False
validate a url for a builder.
Builder urls must be http://host/ or http://host:port/ (with or without the trailing slash) only.
>>> valid_builder_url('http://example.com:54321/') True >>> valid_builder_url('http://example.com/foo') False >>> valid_builder_url('ftp://foo.com/') False
Returns a boolean stating whether 'url' is a valid URL.
None and an empty string are not valid URLs:
>>> validate_url(None, []) False >>> validate_url('', []) False
The valid_schemes list is checked:
>>> validate_url('http://example.com', ['http']) True >>> validate_url('http://example.com', ['https', 'ftp']) False
A URL without a host name is not valid:
>>> validate_url('http://', ['http']) False
Unicode urls are converted to ascii for checking. Failure to convert results in failure.
>>> validate_url(u'http://example.com', ['http']) True >>> validate_url(u'http://example.com/test\u2026', ['http']) False
Returns True if web_ref is a valid download URL, or raises a LaunchpadValidationError.
>>> valid_webref('http://example.com') True >>> valid_webref('https://example.com/foo/bar') True >>> valid_webref('ftp://example.com/~ming') True >>> valid_webref('sftp://example.com//absolute/path/maybe') True >>> valid_webref('other://example.com/moo') Traceback (most recent call last): ... LaunchpadValidationError: ...