Exemple #1
0
    def validate(input, spec):
        if not input and (not spec.get('required', None) or spec.get('default', None)):
            return

        if not input.isdigit():
            raise validation.ValidationError(len(input), 'Not a number')

        enum = spec.get('enum')
        try:
            enum[int(input)]
        except IndexError:
            raise validation.ValidationError(len(input), 'Out of bounds')
Exemple #2
0
    def validate(input, spec):
        if not input and (not spec.get("required", None)
                          or spec.get("default", None)):
            return

        if not input.isdigit():
            raise validation.ValidationError(len(input), "Not a number")

        enum = spec.get("enum")
        try:
            enum[int(input)]
        except IndexError:
            raise validation.ValidationError(len(input), "Out of bounds")
Exemple #3
0
    def validate(input, spec):
        if input:
            try:
                input = int(input)
            except ValueError as e:
                raise validation.ValidationError(len(input), str(e))

            super(IntegerReader, IntegerReader).validate(input, spec)
Exemple #4
0
    def validate(input, spec):
        if input:
            try:
                input = float(input)
            except ValueError as e:
                raise validation.ValidationError(len(input), str(e))

            super(NumberReader, NumberReader).validate(input, spec)
Exemple #5
0
    def validate(input, spec):
        if not input and (not spec.get('required', None) or spec.get('default', None)):
            return

        if input.lower() not in POSITIVE_BOOLEAN | NEGATIVE_BOOLEAN:
            raise validation.ValidationError(len(input),
                                             'Does not look like boolean. Pick from [%s]'
                                             % ', '.join(POSITIVE_BOOLEAN | NEGATIVE_BOOLEAN))
Exemple #6
0
    def validate(input, spec):
        if not input and (not spec.get('required', None) or spec.get('default', None)):
            return

        for m in re.finditer(r'[^, ]+', input):
            index, item = m.start(), m.group()
            try:
                EnumReader.validate(item, spec.get('items', {}))
            except validation.ValidationError as e:
                raise validation.ValidationError(index, str(e))
Exemple #7
0
    def validate(input, spec):
        if not input and (not spec.get("required", None)
                          or spec.get("default", None)):
            return

        for m in re.finditer(r"[^, ]+", input):
            index, item = m.start(), m.group()
            try:
                EnumReader.validate(item, spec.get("items", {}))
            except validation.ValidationError as e:
                raise validation.ValidationError(index, six.text_type(e))
Exemple #8
0
 def validate(input, spec):
     try:
         jsonschema.validate(input, spec, Draft3Validator)
     except jsonschema.ValidationError as e:
         raise validation.ValidationError(len(input), str(e))
Exemple #9
0
 def validate(input, spec):
     if input.lower() not in POSITIVE_BOOLEAN | NEGATIVE_BOOLEAN:
         raise validation.ValidationError(
             len(input), 'Does not look like boolean. Pick from [%s]' %
             ', '.join(POSITIVE_BOOLEAN | NEGATIVE_BOOLEAN))