fc8a8ecbf0250a018986921dbdb374c823c8c082
[nepi.git] / src / nepi / util / validation.py
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3
4 import ipaddr
5
6 def is_bool(value):
7     return isinstance(value, bool)
8
9 def is_integer(value):
10     return isinstance(value, int)
11
12 def is_string(value):
13     return isinstance(value, str)
14
15 def is_ip4_address(value):
16     try:
17         ipaddr.IPv4(value)
18     except ipaddr.Error:
19         return False
20     return True
21
22 def is_ip6_address(value):
23     try:
24         ipaddr.IPv6(value)
25     except ipaddr.Error:
26         return False
27     return True
28