2 # -*- coding: utf-8 -*-
7 def is_enum(attribute, value):
8 return isinstance(value, str) and value in attribute.allowed
10 def is_bool(attribute, value):
11 return isinstance(value, bool)
13 def is_double(attribute, value):
14 return isinstance(value, float)
16 def is_integer(attribute, value, min=None, max=None):
17 if not isinstance(value, int):
19 if min is not None and value < min:
21 if max is not None and value > max:
25 def is_integer_range(min=None, max=None):
26 def is_integer_range(attribute, value):
27 if not isinstance(value, int):
29 if min is not None and value < min:
31 if max is not None and value > max:
34 return is_integer_range
37 def is_string(attribute, value):
38 return isinstance(value, str)
40 def is_time(attribute, value):
41 return isinstance(value, str) # TODO: Missing validation!
43 def is_ip4_address(attribute, value):
45 ipaddr.IPv4Address(value)
46 except ipaddr.AddressValueError:
50 def is_ip6_address(attribute, value):
52 ipaddr.IPv6Address(value)
53 except ipaddr.AddressValueError:
57 # TODO: Allow netrefs!
58 def is_ip_address(attribute, value):
59 if not is_ip4_address(attribute, value) and \
60 not is_ip6_address(attribute, value):
64 def is_mac_address(attribute, value):
65 regex = r'^([0-9a-zA-Z]{0,2}:)*[0-9a-zA-Z]{0,2}'
66 found = re.search(regex, value)
67 if not found or value.count(':') != 5: