Beispiel #1
0
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))
Beispiel #2
0
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)
Beispiel #3
0
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))
Beispiel #4
0
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)
Beispiel #5
0
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
Beispiel #6
0
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
Beispiel #7
0
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))
Beispiel #8
0
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))
Beispiel #9
0
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
Beispiel #10
0
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)
Beispiel #11
0
def validate_count(ctx, param, value):
    if value < 0 or value % 2 != 0:
        raise click.BadParameter('Should be a positive, even integer.')
    return value
Beispiel #12
0
 def validate_pos_int(ctx, param, value):
     if value < 0:
         raise click.BadParameter("Value needs to be positive")
     return value
Beispiel #13
0
    def validate(ctx, param, value):
        if value < 0:
            raise click.BadParameter("should be positive")

        return value