def convert_flip(ctx, param, value): if value is None: return value = value.lower() if value in ("lr", "leftright"): return (Image.FLIP_LEFT_RIGHT, "left to right") if value in ("tb", "topbottom", "upsidedown", "ud"): return (Image.FLIP_LEFT_RIGHT, "top to bottom") raise click.BadParameter("invalid flip '{}'".format(value))
def convert_flip(ctx, param, value): if value is None: return value = value.lower() if value in ('lr', 'leftright'): return (Image.FLIP_LEFT_RIGHT, 'left to right') if value in ('tb', 'topbottom', 'upsidedown', 'ud'): return (Image.FLIP_LEFT_RIGHT, 'top to bottom') raise click.BadParameter('invalid flip "%s"' % value)
def convert_rotation(ctx, param, value): if value is None: return value = value.lower() if value in ("90", "r", "right"): return (Image.ROTATE_90, 90) if value in ("180", "-180"): return (Image.ROTATE_180, 180) if value in ("-90", "270", "l", "left"): return (Image.ROTATE_270, 270) raise click.BadParameter("invalid rotation '{}'".format(value))
def convert_rotation(ctx, param, value): if value is None: return value = value.lower() if value in ('90', 'r', 'right'): return (Image.ROTATE_90, 90) if value in ('180', '-180'): return (Image.ROTATE_180, 180) if value in ('-90', '270', 'l', 'left'): return (Image.ROTATE_270, 270) raise click.BadParameter('invalid rotation "%s"' % value)
def validateExchange(ctx: Context, option: Option, ixValue: int) -> int: if ixValue is not None and ( (type(ixValue) != int) or (ixValue not in range(state.ixLowValue, (state.ixHighValue + 1)))): raise click.BadParameter( f"{ixValue} - must be an integer between {state.ixLowValue} and {state.ixHighValue}." ) sys.exit(1) return ixValue
def validateAsn(ctx: Context, option: Option, asnValue: int) -> int: if asnValue is not None and ( (type(asnValue) != int) or (asnValue not in range(state.asnLowValue, (state.asnHighValue + 1)))): raise click.BadParameter( f"{asnValue} - must be an integer between {state.asnLowValue} and {state.asnHighValue}." ) sys.exit(1) return asnValue
def cli(count, foo, url): """Validation. This example validates parameters in different ways. It does it through callbacks, through a custom type as well as by validating manually in the function. """ if foo is not None and foo != 'wat': raise click.BadParameter( 'If a value is provided it needs to be the ' 'value "wat".', param_hint=['--foo']) click.echo('count: %s' % count) click.echo('foo: %s' % foo) click.echo('url: %s' % repr(url))
def cli(count, foo, url): """Validation. This example validates parameters in different ways. It does it through callbacks, through a custom type as well as by validating manually in the function. """ if foo is not None and foo != "wat": raise click.BadParameter( 'If a value is provided it needs to be the value "wat".', param_hint=["--foo"], ) click.echo("count: {}".format(count)) click.echo("foo: {}".format(foo)) click.echo("url: {!r}".format(url))
def validatePrefix( ctx: Context, option: Option, prefixValue: Union[IPv4Network, IPv6Network] ) -> Union[IPv4Network, IPv6Network]: validPrefix: Union[IPv4Network, IPv6Network] = None if prefixValue is not None: try: validPrefix = ipaddress.ip_network(prefixValue) except Exception: raise click.BadParameter( f"{prefixValue} is an invalid network/mask.") sys.exit(1) return validPrefix
def validate_uf_codes_parameter( ctx: Optional[click.Context] = None, param: Optional[Iterable[Any]] = None, value: Tuple[str] = lambda: tuple(), ) -> Tuple[str]: valid_codes = [] invalid_codes = [] for tentative in value: try: valid_codes.append(validate_tentative_uf_code(tentative)) except (TypeError, ValueError): invalid_codes.append(tentative) if invalid_codes: raise click.BadParameter(f"Found invalid UF code: {invalid_codes}") return tuple(valid_codes)
def validate_count(ctx, param, value): if value < 0 or value % 2 != 0: raise click.BadParameter('Should be a positive, even integer.') return value
def validate_pos_int(ctx, param, value): if value < 0: raise click.BadParameter("Value needs to be positive") return value
def validate(ctx, param, value): if value < 0: raise click.BadParameter("should be positive") return value