Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1from pyramid.compat import string_types 

2 

3truthy = frozenset(('t', 'true', 'y', 'yes', 'on', '1')) 

4falsey = frozenset(('f', 'false', 'n', 'no', 'off', '0')) 

5 

6 

7def asbool(s): 

8 """ Return the boolean value ``True`` if the case-lowered value of string 

9 input ``s`` is a :term:`truthy string`. If ``s`` is already one of the 

10 boolean values ``True`` or ``False``, return it.""" 

11 if s is None: 

12 return False 

13 if isinstance(s, bool): 

14 return s 

15 s = str(s).strip() 

16 return s.lower() in truthy 

17 

18 

19def aslist_cronly(value): 

20 if isinstance(value, string_types): 

21 value = filter(None, [x.strip() for x in value.splitlines()]) 

22 return list(value) 

23 

24 

25def aslist(value, flatten=True): 

26 """ Return a list of strings, separating the input based on newlines 

27 and, if flatten=True (the default), also split on spaces within 

28 each line.""" 

29 values = aslist_cronly(value) 

30 if not flatten: 

31 return values 

32 result = [] 

33 for value in values: 

34 subvalues = value.split() 

35 result.extend(subvalues) 

36 return result