~ubuntu-branches/ubuntu/hardy/pastedeploy/hardy

« back to all changes in this revision

Viewing changes to paste/deploy/converters.py

  • Committer: Bazaar Package Importer
  • Author(s): Piotr Ozarowski
  • Date: 2006-05-14 03:27:56 UTC
  • Revision ID: james.westby@ubuntu.com-20060514032756-qqd7u23ijat2ccbf
Tags: upstream-0.5
ImportĀ upstreamĀ versionĀ 0.5

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
def asbool(obj):
 
2
    if isinstance(obj, (str, unicode)):
 
3
        obj = obj.strip().lower()
 
4
        if obj in ['true', 'yes', 'on', 'y', 't', '1']:
 
5
            return True
 
6
        elif obj in ['false', 'no', 'off', 'n', 'f', '0']:
 
7
            return False
 
8
        else:
 
9
            raise ValueError(
 
10
                "String is not true/false: %r" % obj)
 
11
    return bool(obj)
 
12
 
 
13
def aslist(obj, sep=None, strip=True):
 
14
    if isinstance(obj, (str, unicode)):
 
15
        lst = obj.split(sep)
 
16
        if strip:
 
17
            lst = [v.strip() for v in lst]
 
18
        return lst
 
19
    elif isinstance(obj, (list, tuple)):
 
20
        return obj
 
21
    elif obj is None:
 
22
        return []
 
23
    else:
 
24
        return [obj]