Christoph Haas <[EMAIL PROTECTED]> writes:
> I could contribute validators for:
>
> - valid IPv4 network/address specifications
> (e.g. "10.0.0.0/8" or "192.168.25.1" but not "1.2.3.4/123")
Here is what I use for IPv4 addr ranges:
from formencode import validators
import iplib
class CIDRValidator(validators.UnicodeString):
""" An IP range in CIDR notation. Single IP accepted without the
'/32' qualifier. An iplib.CIDR object is returned. """
def _to_python(self, value, state):
if iplib.is_dot(value):
return iplib.CIDR(value+"/32")
try:
return iplib.CIDR(value)
except ValueError:
raise validators.Invalid(
"Must be an IP range in CIDR notation. Ex: '192.168.0.0/24'",
val,
state)
It requires iplib which plays badly with easy_install but it's a
single python file so I repackage it in my project.
--
Yannick Gingras
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"pylons-discuss" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/pylons-discuss?hl=en
-~----------~----~----~----~------~----~------~--~---