l.a.v.url : module documentation

Part of lp.app.validators

No module docstring
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
def valid_absolute_url(name):

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
def valid_builder_url(url):

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
def builder_url_validator(url):
Return True if the url is valid, or raise a LaunchpadValidationError
def validate_url(url, valid_schemes):

Returns a boolean stating whether 'url' is a valid URL.

A URL is valid if:
  • its URL scheme is in the provided 'valid_schemes' list, and
  • it has a non-empty host name.

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
def valid_webref(web_ref):

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: ...
API Documentation for Launchpad, generated by pydoctor at 2018-05-22 00:00:04.