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')
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")
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)
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)
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))
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))
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))
def validate(input, spec): try: jsonschema.validate(input, spec, Draft3Validator) except jsonschema.ValidationError as e: raise validation.ValidationError(len(input), str(e))
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))