Docs for IS_IPV4

[ Python Tutorial ] [ Python Libraries ] [ web2py epydoc ]

Description


<type 'type'> extends (<class 'gluon.validators.Validator'>,)



































































































Checks if field's value is an IP version 4 address in decimal form. Can
be set to force addresses from certain range.

IPv4 regex taken from: http://regexlib.com/REDetails.aspx?regexp_id=1411

Args:

minip: lowest allowed address; accepts:

-
str, eg. 192.168.0.1
- list or tuple of octets, eg. [192, 168, 0, 1]
maxip: highest allowed address; same as above
invert: True to allow addresses only from outside of given range; note
that range boundaries are not matched this way
is_localhost: localhost address treatment:

-
None (default): indifferent
- True (enforce): query address must match localhost address (127.0.0.1)
-
False (forbid): query address must not match localhost address
is_private: same as above, except that query address is checked against
two address ranges: 172.16.0.0 - 172.31.255.255 and
192.168.0.0 - 192.168.255.255
is_automatic: same as above, except that query address is checked against
one address range: 169.254.0.0 - 169.254.255.255

Minip and maxip may also be lists or tuples of addresses in all above
forms (str, int, list / tuple), allowing setup of multiple address ranges::

minip = (minip1, minip2, ... minipN)
| | |
| | |
maxip = (maxip1, maxip2, ... maxipN)

Longer iterable will be truncated to match length of shorter one.

Examples:
Check for valid IPv4 address:

INPUT(_type='text', _name='name', requires=IS_IPV4())

Check for valid IPv4 address belonging to specific range:

INPUT(_type='text', _name='name',
requires=IS_IPV4(minip='100.200.0.0', maxip='100.200.255.255'))

Check for valid IPv4 address belonging to either 100.110.0.0 -
100.110.255.255 or 200.50.0.0 - 200.50.0.255 address range:

INPUT(_type='text', _name='name',
requires=IS_IPV4(minip=('100.110.0.0', '200.50.0.0'),
maxip=('100.110.255.255', '200.50.0.255')))

Check for valid IPv4 address belonging to private address space:

INPUT(_type='text', _name='name', requires=IS_IPV4(is_private=True))

Check for valid IPv4 address that is not a localhost address:

INPUT(_type='text', _name='name', requires=IS_IPV4(is_localhost=False))

>>>
IS_IPV4()('1.2.3.4')
(
'1.2.3.4', None)
>>>
IS_IPV4()('255.255.255.255')
(
'255.255.255.255', None)
>>>
IS_IPV4()('1.2.3.4 ')
(
'1.2.3.4 ', 'enter valid IPv4 address')
>>>
IS_IPV4()('1.2.3.4.5')
(
'1.2.3.4.5', 'enter valid IPv4 address')
>>>
IS_IPV4()('123.123')
(
'123.123', 'enter valid IPv4 address')
>>>
IS_IPV4()('1111.2.3.4')
(
'1111.2.3.4', 'enter valid IPv4 address')
>>>
IS_IPV4()('0111.2.3.4')
(
'0111.2.3.4', 'enter valid IPv4 address')
>>>
IS_IPV4()('256.2.3.4')
(
'256.2.3.4', 'enter valid IPv4 address')
>>>
IS_IPV4()('300.2.3.4')
(
'300.2.3.4', 'enter valid IPv4 address')
>>>
IS_IPV4(minip='1.2.3.4', maxip='1.2.3.4')('1.2.3.4')
(
'1.2.3.4', None)
>>>
IS_IPV4(minip='1.2.3.5', maxip='1.2.3.9', error_message='Bad ip')('1.2.3.4')
(
'1.2.3.4', 'bad ip')
>>>
IS_IPV4(maxip='1.2.3.4', invert=True)('127.0.0.1')
(
'127.0.0.1', None)
>>>
IS_IPV4(maxip='1.2.3.4', invert=True)('1.2.3.4')
(
'1.2.3.4', 'enter valid IPv4 address')
>>>
IS_IPV4(is_localhost=True)('127.0.0.1')
(
'127.0.0.1', None)
>>>
IS_IPV4(is_localhost=True)('1.2.3.4')
(
'1.2.3.4', 'enter valid IPv4 address')
>>>
IS_IPV4(is_localhost=False)('127.0.0.1')
(
'127.0.0.1', 'enter valid IPv4 address')
>>>
IS_IPV4(maxip='100.0.0.0', is_localhost=True)('127.0.0.1')
(
'127.0.0.1', 'enter valid IPv4 address')



Attributes


IS_IPV4.__call__ <type 'instancemethod'> belongs to class <type 'instancemethod'>

IS_IPV4.__class__ <type 'type'> extends (<type 'object'>,) belongs to class <type 'type'>
type(object) -> the object's type type(name, bases, dict) -> a new type

IS_IPV4.__delattr__ <type 'wrapper_descriptor'> belongs to class <type 'wrapper_descriptor'>
x.__delattr__('name') <==> del x.name

IS_IPV4.__dict__ <type 'dictproxy'> belongs to class <type 'dictproxy'>

IS_IPV4.__doc__ <type 'str'> belongs to class <type 'str'>
str(object='') -> string Return a nice string representation of the object. If the argument is a string, the return value is the same object.

IS_IPV4.__format__ <type 'method_descriptor'> belongs to class <type 'method_descriptor'>
default object formatter

IS_IPV4.__getattribute__ <type 'wrapper_descriptor'> belongs to class <type 'wrapper_descriptor'>
x.__getattribute__('name') <==> x.name

IS_IPV4.__hash__ <type 'wrapper_descriptor'> belongs to class <type 'wrapper_descriptor'>
x.__hash__() <==> hash(x)

IS_IPV4.__init__ <type 'instancemethod'> belongs to class <type 'instancemethod'>

IS_IPV4.__module__ <type 'str'> belongs to class <type 'str'>
str(object='') -> string Return a nice string representation of the object. If the argument is a string, the return value is the same object.

IS_IPV4.__new__ <type 'builtin_function_or_method'> belongs to class <type 'builtin_function_or_method'>
T.__new__(S, ...) -> a new object with type S, a subtype of T

IS_IPV4.__reduce__ <type 'method_descriptor'> belongs to class <type 'method_descriptor'>
helper for pickle

IS_IPV4.__reduce_ex__ <type 'method_descriptor'> belongs to class <type 'method_descriptor'>
helper for pickle

IS_IPV4.__repr__ <type 'wrapper_descriptor'> belongs to class <type 'wrapper_descriptor'>
x.__repr__() <==> repr(x)

IS_IPV4.__setattr__ <type 'wrapper_descriptor'> belongs to class <type 'wrapper_descriptor'>
x.__setattr__('name', value) <==> x.name = value

IS_IPV4.__sizeof__ <type 'method_descriptor'> belongs to class <type 'method_descriptor'>
__sizeof__() -> int size of object in memory, in bytes

IS_IPV4.__str__ <type 'wrapper_descriptor'> belongs to class <type 'wrapper_descriptor'>
x.__str__() <==> str(x)

IS_IPV4.__subclasshook__ <type 'builtin_function_or_method'> belongs to class <type 'builtin_function_or_method'>
Abstract classes can override this to customize issubclass(). This is invoked early on by abc.ABCMeta.__subclasscheck__(). It should return True, False or NotImplemented. If it returns NotImplemented, the normal algorithm is used. Otherwise, it overrides the normal algorithm (and the outcome is cached).

IS_IPV4.__weakref__ <type 'getset_descriptor'> belongs to class <type 'getset_descriptor'>
list of weak references to the object (if defined)

IS_IPV4.automatic <type 'tuple'> belongs to class <type 'tuple'>
tuple() -> empty tuple tuple(iterable) -> tuple initialized from iterable's items If the argument is a tuple, the return value is the same object.

IS_IPV4.formatter <type 'instancemethod'> belongs to class <type 'instancemethod'>
For some validators returns a formatted version (matching the validator) of value. Otherwise just returns the value.

IS_IPV4.localhost <type 'int'> belongs to class <type 'int'>
int(x=0) -> int or long int(x, base=10) -> int or long Convert a number or string to an integer, or return 0 if no arguments are given. If x is floating point, the conversion truncates towards zero. If x is outside the integer range, the function returns a long instead. If x is not a number or if base is given, then x must be a string or Unicode object representing an integer literal in the given base. The literal can be preceded by '+' or '-' and be surrounded by whitespace. The base defaults to 10. Valid bases are 0 and 2-36. Base 0 means to interpret the base from the string as an integer literal. >>> int('0b100', base=0) 4

IS_IPV4.numbers <type 'tuple'> belongs to class <type 'tuple'>
tuple() -> empty tuple tuple(iterable) -> tuple initialized from iterable's items If the argument is a tuple, the return value is the same object.

IS_IPV4.private <type 'tuple'> belongs to class <type 'tuple'>
tuple() -> empty tuple tuple(iterable) -> tuple initialized from iterable's items If the argument is a tuple, the return value is the same object.

IS_IPV4.regex <type '_sre.SRE_Pattern'> belongs to class <type '_sre.SRE_Pattern'>
Compiled regular expression objects