1# (c) 2005 Ian Bicking and contributors; written for Paste (http://pythonpaste.org)
2# Licensed under the MIT license: http://www.opensource.org/licenses/mit-license.php
3
4import six
5
6
7def asbool(obj):
8    if isinstance(obj, (six.binary_type, six.text_type)):
9        obj = obj.strip().lower()
10        if obj in ['true', 'yes', 'on', 'y', 't', '1']:
11            return True
12        elif obj in ['false', 'no', 'off', 'n', 'f', '0']:
13            return False
14        else:
15            raise ValueError(
16                "String is not true/false: %r" % obj)
17    return bool(obj)
18
19def aslist(obj, sep=None, strip=True):
20    if isinstance(obj, (six.binary_type, six.text_type)):
21        lst = obj.split(sep)
22        if strip:
23            lst = [v.strip() for v in lst]
24        return lst
25    elif isinstance(obj, (list, tuple)):
26        return obj
27    elif obj is None:
28        return []
29    else:
30        return [obj]
31