#NEWLINE# def bool_from_string( subject , strict = False ) : #NEWLINE# #INDENT# "Interpret a string as a boolean.\n\n    A case-insensitive match is performed such that strings matching 't',\n    'true', 'on', 'y', 'yes', or '1' are considered True and, when\n    `strict=False`, anything else is considered False.\n\n    Useful for JSON-decoded stuff and config file parsing.\n\n    If `strict=True`, unrecognized values, including None, will raise a\n    ValueError which is useful when parsing values passed in from an API call.\n    Strings yielding False are 'f', 'false', 'off', 'n', 'no', or '0'.\n    " #NEWLINE# if ( not isinstance ( subject , six . string_types ) ) : #NEWLINE# #INDENT# subject = str ( subject ) #NEWLINE# #UNINDENT# lowered = subject . strip ( ) . lower ( ) #NEWLINE# if ( lowered in TRUE_STRINGS ) : #NEWLINE# #INDENT# return True #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( lowered in FALSE_STRINGS ) : #NEWLINE# #INDENT# return False #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if strict : #NEWLINE# #INDENT# acceptable = ', ' . join ( ( ( "'%s'" % s ) for s in sorted ( ( TRUE_STRINGS + FALSE_STRINGS ) ) ) ) #NEWLINE# msg = ( _ ( "Unrecognized value '%(val)s', acceptable values are: %(acceptable)s" ) % { #NEWLINE# #INDENT# 'val' : subject , #NEWLINE# 'acceptable' : acceptable , #NEWLINE# #UNINDENT# } ) #NEWLINE# raise ValueError ( msg ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# return False