コード例 #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')
コード例 #2
0
ファイル: interactive.py プロジェクト: st2sandbox/st2
    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")
コード例 #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)
コード例 #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)
コード例 #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))
コード例 #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))
コード例 #7
0
ファイル: interactive.py プロジェクト: st2sandbox/st2
    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))
コード例 #8
0
 def validate(input, spec):
     try:
         jsonschema.validate(input, spec, Draft3Validator)
     except jsonschema.ValidationError as e:
         raise validation.ValidationError(len(input), str(e))
コード例 #9
0
ファイル: interactive.py プロジェクト: neufeldtech/st2
 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))