Revision 1233
Added by Aaron Marcuse-Kubitza almost 13 years ago
util.py | ||
---|---|---|
16 | 16 |
|
17 | 17 |
def root_module(value): return module(value)[0] |
18 | 18 |
|
19 |
#### Type checking |
|
19 |
#### Type checking and conversion
|
|
20 | 20 |
|
21 | 21 |
class ConstraintError(ValueError): |
22 | 22 |
def __init__(self, check_func, value): |
... | ... | |
29 | 29 |
if val != None and not isinstance(val, type_): val = type_(val) |
30 | 30 |
return val |
31 | 31 |
|
32 |
def all_not_none(vals): return reduce(and_, map(lambda v: v != None, vals)) |
|
33 |
|
|
32 | 34 |
def is_str(val): return isinstance(val, basestring) |
33 | 35 |
|
34 | 36 |
def is_list(val): return isinstance(val, list) |
35 | 37 |
|
38 |
def bool2str(val): |
|
39 |
if val: return '1' |
|
40 |
else: return '' |
|
41 |
|
|
36 | 42 |
#### Basic types |
37 | 43 |
|
38 | 44 |
def none_if(val, none_val): |
Also available in: Unified diff
util.py: Added all_not_none() and bool2str()