def toBoolean()

in scripts/yapl/Utilities.py [0:0]


def toBoolean (arg):
  """
    Return True or False depending on the value of arg.
 
    Canonicalize all the ways you can think of representing a boolean into a 1 or 0.  
    This is convenient for use with values that ultimately originated from a user, e.g., 
    from a property file where the user may enter y, yes, n, no, t, f
    etc, to represent true or false.
 
  """
  if (not arg): return False
  if (arg == 1): return True
  if (isinstance(arg, (str, unicode))):
    if (re.match('^(true|t|yes|y|1)$', arg, flags=re.IGNORECASE)): return True
    if (re.match('^(false|f|no|n|0)$', arg, flags=re.IGNORECASE)): return False
  #endIf
  raise Exception("toBoolean: Unknown boolean value: %s" % arg)