def parse_bool(section, optionname):
    """
    Parses a string option as bool. Possible options are "True"/"False",
    "yes"/"no", "1"/"0".
    """
    string = section.dict[optionname]
    if string.lower() == "true" or string.lower() == "yes":
        return True
    elif string.lower() == "false" or string.lower() == "no":
        return False
    elif string.isdigit():
        return bool(int(string))
    else:
        raise ValueError("Option " + optionname + " in section " + section.name
                         + " is not a valid boolean!")