def gen_bool_parse(val):
    """Convert a string, as a human might type it, to a boolean. Unrecognized
    values raise an exception.
    """
    val = val.strip()
    if not val:
        return False
    try:
        return bool(int(val))
    except:
        pass
    ch = val[0]
    if ch in {'t', 'T', 'y', 'Y'}:
        return True
    if ch in {'f', 'F', 'n', 'N'}:
        return False
    raise ValueError('"%s" does not look like a boolean' % (val,))