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_number(attribute, value):
17 return isinstance(value, (float,int,long))
19 def is_integer(attribute, value, min=None, max=None):
20 if not isinstance(value, int):
22 if min is not None and value < min:
24 if max is not None and value > max:
28 def is_integer_range(min=None, max=None):
29 def is_integer_range(attribute, value):
30 if not isinstance(value, int):
32 if min is not None and value < min:
34 if max is not None and value > max:
37 return is_integer_range
39 def is_number_range(min=None, max=None):
40 def is_number_range(attribute, value):
41 if not isinstance(value, (float,int,long)):
43 if min is not None and value < min:
45 if max is not None and value > max:
48 return is_number_range
51 def is_string(attribute, value):
52 return isinstance(value, str)
54 def is_time(attribute, value):
55 return isinstance(value, str) # TODO: Missing validation!
57 def is_ip4_address(attribute, value):
59 ipaddr.IPv4Address(value)
60 except ipaddr.AddressValueError:
64 def is_ip6_address(attribute, value):
66 ipaddr.IPv6Address(value)
67 except ipaddr.AddressValueError:
71 def is_ip_address(attribute, value):
72 if not is_ip4_address(attribute, value) and \
73 not is_ip6_address(attribute, value):
77 # TODO: Allow netrefs!
78 def is_ref_address(attribute, value):
79 if not is_ip4_address(attribute, value) and \
80 not is_ip6_address(attribute, value):
84 def is_mac_address(attribute, value):
85 regex = r'^([0-9a-zA-Z]{0,2}:)*[0-9a-zA-Z]{0,2}'
86 found = re.search(regex, value)
87 if not found or value.count(':') != 5: