URL

Validate a URL, either http://... or https://. If check_exists is true, then we'll actually make a request for the page.

If add_http is true, then if no scheme is present we'll add http://

>>> u = URL(add_http=True)
>>> u.to_python('foo.com')
'http://foo.com'
>>> u.to_python('http://hahaha/bar.html')
'http://hahaha/bar.html'
>>> u.to_python('https://test.com')
'https://test.com'
>>> u = URL(add_http=False, check_exists=True)
>>> u.to_python('http://google.com')
'http://google.com'
>>> u.to_python('http://colorstudy.com/doesnotexist.html')
Traceback (most recent call last):
    ...
Invalid: The server responded that the page could not be found
>>> u.to_python('http://this.domain.does.not.exists.formencode.org/test.html')
Traceback (most recent call last):
    ...
Invalid: An error occured when trying to connect to the server: ...

Messages

badType:
The input must be a string (not a %(type)s: %(value)r)
badURL:
That is not a valid URL
empty:
Please enter a value
httpError:
An error occurred when trying to access the URL: %(error)s
noScheme:
You must start your URL with http://, https://, etc
noneType:
The input must be a string (not None)
notFound:
The server responded that the page could not be found
socketError:
An error occured when trying to connect to the server: %(error)s
status:
The server responded with a bad status code (%(status)s)

Attributes

a gettextargs

{}

a strip

False

a check_exists

False

a accept_python

True

a url_re

<_sre.SRE_Pattern object at 0x883c538>

a __singletonmethods__

('to_python', 'from_python', 'message', 'all_messages', 'subvalidators')

a add_http

True

a declarative_count

31

a use_builtins_gettext

True

a __unpackargs__

()

a compound

False

a not_empty

False

a scheme_re

<_sre.SRE_Pattern object at 0xb77aada0>

a __mutableattributes__

()

a repeating

False

Methods

f __initargs__(self, new_attrs) ...

f __call__(self, *args, **kw) ...

f __classinit__(cls, new_attrs) ...

f __init__(self, *args, **kw) ...

f __sourcerepr__(self, source, binding=None) ...

f __classsourcerepr__(cls, source, binding=None) ...

See the source for more information.