1
|
|
|
# -*- coding: utf-8 -*- |
2
|
|
|
|
3
|
|
|
from datetime import datetime |
4
|
|
|
from decimal import Decimal |
5
|
|
|
from six import integer_types, string_types |
6
|
|
|
|
7
|
|
|
import re |
8
|
|
|
|
9
|
|
|
regex = re.compile('').__class__ |
10
|
|
|
|
11
|
|
|
|
12
|
|
|
def is_bool(val): |
13
|
|
|
return isinstance(val, bool) |
14
|
|
|
|
15
|
|
|
|
16
|
|
|
def is_collection(val): |
17
|
|
|
return isinstance(val, (dict, list, set, tuple, )) |
18
|
|
|
|
19
|
|
|
|
20
|
|
|
def is_datetime(val): |
21
|
|
|
return isinstance(val, datetime) |
22
|
|
|
|
23
|
|
|
|
24
|
|
|
def is_decimal(val): |
25
|
|
|
return isinstance(val, Decimal) |
26
|
|
|
|
27
|
|
|
|
28
|
|
|
def is_dict(val): |
29
|
|
|
return isinstance(val, dict) |
30
|
|
|
|
31
|
|
|
|
32
|
|
|
def is_dict_or_list(val): |
33
|
|
|
return isinstance(val, (dict, list, )) |
34
|
|
|
|
35
|
|
|
|
36
|
|
|
def is_float(val): |
37
|
|
|
return isinstance(val, float) |
38
|
|
|
|
39
|
|
|
|
40
|
|
|
def is_function(val): |
41
|
|
|
return callable(val) |
42
|
|
|
|
43
|
|
|
|
44
|
|
|
def is_integer(val): |
45
|
|
|
return isinstance(val, integer_types) |
46
|
|
|
|
47
|
|
|
|
48
|
|
|
def is_json_serializable(val): |
49
|
|
|
json_types = (type(None), bool, dict, float, list, tuple, ) + \ |
50
|
|
|
integer_types + string_types |
51
|
|
|
return isinstance(val, json_types) |
52
|
|
|
|
53
|
|
|
|
54
|
|
|
def is_list(val): |
55
|
|
|
return isinstance(val, list) |
56
|
|
|
|
57
|
|
|
|
58
|
|
|
def is_list_or_tuple(val): |
59
|
|
|
return isinstance(val, (list, tuple, )) |
60
|
|
|
|
61
|
|
|
|
62
|
|
|
def is_none(val): |
63
|
|
|
return val is None |
64
|
|
|
|
65
|
|
|
|
66
|
|
|
def is_not_none(val): |
67
|
|
|
return val is not None |
68
|
|
|
|
69
|
|
|
|
70
|
|
|
def is_regex(val): |
71
|
|
|
return isinstance(val, regex) |
72
|
|
|
|
73
|
|
|
|
74
|
|
|
def is_set(val): |
75
|
|
|
return isinstance(val, set) |
76
|
|
|
|
77
|
|
|
|
78
|
|
|
def is_string(val): |
79
|
|
|
return isinstance(val, string_types) |
80
|
|
|
|
81
|
|
|
|
82
|
|
|
def is_tuple(val): |
83
|
|
|
return isinstance(val, tuple) |
84
|
|
|
|