CIDR

Formencode validator to check whether a string is in correct CIDR notation (IP address, or IP address plus /mask)

Examples:

>>> cidr = CIDR()
>>> cidr.to_python('127.0.0.1')
'127.0.0.1'
>>> cidr.to_python('299.0.0.1')
Traceback (most recent call last):
    ...
Invalid: The octets must be within the range of 0-255 (not '299')
>>> cidr.to_python('192.168.0.1/1')
Traceback (most recent call last):
    ...
Invalid: The network size (bits) must be within the range of 8-32 (not '1')
>>> cidr.to_python('asdf')
Traceback (most recent call last):
    ...
Invalid: Please enter a valid IP address (a.b.c.d) or IP network (a.b.c.d/e)

Messages

badType:
The input must be a string (not a %(type)s: %(value)r)
empty:
Please enter a value
illegal_bits:
The network size (bits) must be within the range of 8-32 (not %(bits)r)
illegal_octets:
The octets must be within the range of 0-255 (not %(octet)r)
noneType:
The input must be a string (not None)
not_cidr_format:
Please enter a valid IP address (a.b.c.d) or IP network (a.b.c.d/e)

Attributes

a gettextargs

{}

a strip

False

a use_builtins_gettext

True

a accept_python

True

a __singletonmethods__

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

a declarative_count

43

a __unpackargs__

()

a compound

False

a not_empty

False

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) ...

f validate_python(self, value, state) ...

See the source for more information.