def asbool(val):
    """Converts a value into a boolean

    :param val: value to convert; accepts a wide range of
        possible representations, such as yes, no, true, false, on, off

    :return: True of val maps to true, False otherwise
    :rtype: boolean
    """
    if val is None:
        return False
    if isinstance(val, bool):
        return val
    val = str(val).strip().lower()
    return val in ("t", "true", "y", "yes", "on", "1")