def choice_validator(optdict, name, value): """validate and return a converted value for option of type 'choice' """ if not value in optdict['choices']: msg = "option %s: invalid value: %r, should be in %s" raise optparse.OptionValueError(msg % (name, value, optdict['choices'])) return value
def choice_validator(optdict: Dict[str, Any], name: str, value: str) -> str: """validate and return a converted value for option of type 'choice'""" if value not in optdict["choices"]: msg = "option %s: invalid value: %r, should be in %s" raise optik_ext.OptionValueError(msg % (name, value, optdict["choices"])) return value
def multiple_choice_validator(optdict, name, value): """validate and return a converted value for option of type 'choice' """ choices = optdict['choices'] values = optparse.check_csv(None, name, value) for value in values: if not value in choices: msg = "option %s: invalid value: %r, should be in %s" raise optparse.OptionValueError(msg % (name, value, choices)) return values
def multiple_choice_validator(optdict: Dict[str, Any], name: str, value: _ValueType) -> _ValueType: """validate and return a converted value for option of type 'choice'""" choices = optdict["choices"] values = optik_ext.check_csv(None, name, value) for value in values: if value not in choices: msg = "option %s: invalid value: %r, should be in %s" raise optik_ext.OptionValueError(msg % (name, value, choices)) return values
def _call_validator(opttype, optdict, option, value): if opttype not in VALIDATORS: raise Exception('Unsupported type "%s"' % opttype) try: return VALIDATORS[opttype](optdict, option, value) except TypeError: try: return VALIDATORS[opttype](value) except optparse.OptionValueError: raise except: raise optparse.OptionValueError('%s value (%r) should be of type %s' % (option, value, opttype))
def _call_validator( opttype: str, optdict: Dict[str, Any], option: str, value: Union[List[str], int, str]) -> Union[List[str], int, str]: if opttype not in VALIDATORS: raise Exception('Unsupported type "%s"' % opttype) try: return VALIDATORS[opttype](optdict, option, value) except TypeError: try: return VALIDATORS[opttype](value) except optik_ext.OptionValueError: raise except Exception: raise optik_ext.OptionValueError( "%s value (%r) should be of type %s" % (option, value, opttype))