def comma_seperated_multiple_choices(argument, values): try: value_list = argument.lower().split(',') value_list = [x.strip() for x in value_list] except AttributeError: raise ValueError('must supply an argument; choose from %s' % directives.format_values(values)) if len(set(value_list) - set(values)) == 0: return ','.join(value_list) else: raise ValueError('"%s" unknown; choose from %s' % (argument, directives.format_values(values)))
def choice(argument, values): """ Like docutils.parsers.rst.directives.choice but adjusted error reporting. """ try: value = argument.lower().strip() except AttributeError: raise ValueError('must supply an argument; choose from %s' % directives.format_values(values)) if value in values: return value elif value: raise ValueError('"%s" unknown; choose from %s' % (argument, directives.format_values(values))) else: raise ValueError('choose from %s' % (directives.format_values(values)))
def nested(argument: ty.Optional[str]) -> ty.Optional[str]: values = (NESTED_FULL, NESTED_SHORT, NESTED_NONE, None) if argument not in values: raise ValueError( "%s is not a valid value for ':nested:'; allowed values: %s" % directives.format_values(values)) return argument
def nested(argument): values = (NESTED_FULL, NESTED_SHORT, NESTED_NONE) if not argument: return None if argument not in values: raise ValueError( "%s is not a valid value for ':nested:'; allowed values: %s" % directives.format_values(values)) return argument
def nested_option(argument: str) -> Optional[str]: # noqa: D103 if not argument: return None values = (NESTED_FULL, NESTED_SHORT, NESTED_NONE) if argument not in values: value = directives.format_values(values) raise ValueError(f"{value} is not a valid value for ':nested:'; allowed values: {value}") return argument