Python jsonschema.exceptions.FormatError() Examples
The following are 23
code examples of jsonschema.exceptions.FormatError().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
jsonschema.exceptions
, or try the search function
.
Example #1
Source File: json_schemas.py From shipyard with Apache License 2.0 | 6 votes |
def validate_json(json_string, schema): """ invokes the validate function of jsonschema """ schema_dict = json.loads(schema) schema_title = schema_dict['title'] try: validate(json_string, schema_dict) except ValidationError as err: title = 'JSON validation failed: {}'.format(err.message) description = 'Failed validator: {} : {}'.format( err.validator, err.validator_value ) LOG.error(title) LOG.error(description) raise InvalidFormatError( title=title, description=description, ) except SchemaError as err: title = 'SchemaError: Unable to validate JSON: {}'.format(err) description = 'Invalid Schema: {}'.format(schema_title) LOG.error(title) LOG.error(description) raise AppError( title=title, description=description ) except FormatError as err: title = 'FormatError: Unable to validate JSON: {}'.format(err) description = 'Invalid Format: {}'.format(schema_title) LOG.error(title) LOG.error(description) raise AppError( title=title, description=description ) # The action resource structure
Example #2
Source File: validators.py From karbor with Apache License 2.0 | 6 votes |
def check(self, param_value, format): """Check whether the param_value conforms to the given format. :argument param_value: the param_value to check :type: any primitive type (str, number, bool) :argument str format: the format that param_value should conform to :raises: :exc:`FormatError` if param_value does not conform to format """ if format not in self.checkers: return # For safety reasons custom checkers can be registered with # allowed exception types. Anything else will fall into the # default formatter. func, raises = self.checkers[format] result, cause = None, None try: result = func(param_value) except raises as e: cause = e if not result: msg = "%r is not a %r" % (param_value, format) raise jsonschema_exc.FormatError(msg, cause=cause)
Example #3
Source File: _format.py From SA-ctf_scoreboard with Creative Commons Zero v1.0 Universal | 6 votes |
def conforms(self, instance, format): """ Check whether the instance conforms to the given format. :argument instance: the instance to check :type: any primitive type (str, number, bool) :argument str format: the format that instance should conform to :rtype: bool """ try: self.check(instance, format) except FormatError: return False else: return True
Example #4
Source File: _format.py From SA-ctf_scoreboard with Creative Commons Zero v1.0 Universal | 6 votes |
def check(self, instance, format): """ Check whether the instance conforms to the given format. :argument instance: the instance to check :type: any primitive type (str, number, bool) :argument str format: the format that instance should conform to :raises: :exc:`FormatError` if instance does not conform to format """ if format not in self.checkers: return func, raises = self.checkers[format] result, cause = None, None try: result = func(instance) except raises as e: cause = e if not result: raise FormatError( "%r is not a %r" % (instance, format), cause=cause, )
Example #5
Source File: validators.py From tacker with Apache License 2.0 | 6 votes |
def check(self, param_value, format): """Check whether the param_value conforms to the given format. :argument param_value: the param_value to check :type: any primitive type (str, number, bool) :argument str format: the format that param_value should conform to :raises: :exc:`FormatError` if param_value does not conform to format """ if format not in self.checkers: return # For safety reasons custom checkers can be registered with # allowed exception types. Anything else will fall into the # default formatter. func, raises = self.checkers[format] result, cause = None, None try: result = func(param_value) except raises as e: cause = e if not result: msg = "%r is not a %r" % (param_value, format) raise jsonschema_exc.FormatError(msg, cause=cause)
Example #6
Source File: validators.py From masakari with Apache License 2.0 | 6 votes |
def check(self, instance, format): """Check whether the instance conforms to the given format. :argument instance: the instance to check :type: any primitive type (str, number, bool) :argument str format: the format that instance should conform to :raises: :exc:`FormatError` if instance does not conform to format """ if format not in self.checkers: return # For safety reasons custom checkers can be registered with # allowed exception types. Anything else will fall into the # default formatter. func, raises = self.checkers[format] result, cause = None, None try: result = func(instance) except raises as e: cause = e if not result: msg = "%r is not a %r" % (instance, format) raise jsonschema_exc.FormatError(msg, cause=cause)
Example #7
Source File: _format.py From Requester with MIT License | 5 votes |
def check(self, instance, format): """ Check whether the instance conforms to the given format. Arguments: instance (any primitive type, i.e. str, number, bool): The instance to check format (str): The format that instance should conform to Raises: :exc:`FormatError` if instance does not conform to ``format`` """ if format not in self.checkers: return func, raises = self.checkers[format] result, cause = None, None try: result = func(instance) except raises as e: cause = e if not result: raise FormatError( "%r is not a %r" % (instance, format), cause=cause, )
Example #8
Source File: _validators.py From SA-ctf_scoreboard with Creative Commons Zero v1.0 Universal | 5 votes |
def format(validator, format, instance, schema): if validator.format_checker is not None: try: validator.format_checker.check(instance, format) except FormatError as error: yield ValidationError(error.message, cause=error.cause)
Example #9
Source File: test_api_validation.py From masakari with Apache License 2.0 | 5 votes |
def test_format_checker_failed_with_non_string(self): checks = ["name"] format_checker = validators.FormatChecker() for check in checks: exc = self.assertRaises(jsonschema_exc.FormatError, format_checker.check, None, "name") self.assertIsInstance(exc.cause, exception.InvalidName) self.assertEqual("An invalid 'name' value was provided. The name " "must be: printable characters. " "Can not start or end with whitespace.", exc.cause.format_message())
Example #10
Source File: test_api_validation.py From masakari with Apache License 2.0 | 5 votes |
def test_format_checker_failed(self): format_checker = validators.FormatChecker() exc = self.assertRaises(jsonschema_exc.FormatError, format_checker.check, " ", "name") self.assertIsInstance(exc.cause, exception.InvalidName) self.assertEqual("An invalid 'name' value was provided. The name must " "be: printable characters. " "Can not start or end with whitespace.", exc.cause.format_message())
Example #11
Source File: _validators.py From Requester with MIT License | 5 votes |
def format(validator, format, instance, schema): if validator.format_checker is not None: try: validator.format_checker.check(instance, format) except FormatError as error: yield ValidationError(error.message, cause=error.cause)
Example #12
Source File: _format.py From Requester with MIT License | 5 votes |
def conforms(self, instance, format): """ Check whether the instance conforms to the given format. Arguments: instance (any primitive type, i.e. str, number, bool): The instance to check format (str): The format that instance should conform to Returns: bool: Whether it conformed """ try: self.check(instance, format) except FormatError: return False else: return True
Example #13
Source File: _format.py From misp42splunk with GNU Lesser General Public License v3.0 | 5 votes |
def check(self, instance, format): """ Check whether the instance conforms to the given format. Arguments: instance (any primitive type, i.e. str, number, bool): The instance to check format (str): The format that instance should conform to Raises: :exc:`FormatError` if instance does not conform to ``format`` """ if format not in self.checkers: return func, raises = self.checkers[format] result, cause = None, None try: result = func(instance) except raises as e: cause = e if not result: raise FormatError( "%r is not a %r" % (instance, format), cause=cause, )
Example #14
Source File: _validators.py From accelerated-data-lake with Apache License 2.0 | 5 votes |
def format(validator, format, instance, schema): if validator.format_checker is not None: try: validator.format_checker.check(instance, format) except FormatError as error: yield ValidationError(error.message, cause=error.cause)
Example #15
Source File: _format.py From accelerated-data-lake with Apache License 2.0 | 5 votes |
def conforms(self, instance, format): """ Check whether the instance conforms to the given format. Arguments: instance (any primitive type, i.e. str, number, bool): The instance to check format (str): The format that instance should conform to Returns: bool: Whether it conformed """ try: self.check(instance, format) except FormatError: return False else: return True
Example #16
Source File: _format.py From accelerated-data-lake with Apache License 2.0 | 5 votes |
def check(self, instance, format): """ Check whether the instance conforms to the given format. Arguments: instance (any primitive type, i.e. str, number, bool): The instance to check format (str): The format that instance should conform to Raises: :exc:`FormatError` if instance does not conform to ``format`` """ if format not in self.checkers: return func, raises = self.checkers[format] result, cause = None, None try: result = func(instance) except raises as e: cause = e if not result: raise FormatError( "%r is not a %r" % (instance, format), cause=cause, )
Example #17
Source File: _validators.py From deepWordBug with Apache License 2.0 | 5 votes |
def format(validator, format, instance, schema): if validator.format_checker is not None: try: validator.format_checker.check(instance, format) except FormatError as error: yield ValidationError(error.message, cause=error.cause)
Example #18
Source File: _format.py From deepWordBug with Apache License 2.0 | 5 votes |
def conforms(self, instance, format): """ Check whether the instance conforms to the given format. Arguments: instance (any primitive type, i.e. str, number, bool): The instance to check format (str): The format that instance should conform to Returns: bool: Whether it conformed """ try: self.check(instance, format) except FormatError: return False else: return True
Example #19
Source File: _format.py From deepWordBug with Apache License 2.0 | 5 votes |
def check(self, instance, format): """ Check whether the instance conforms to the given format. Arguments: instance (any primitive type, i.e. str, number, bool): The instance to check format (str): The format that instance should conform to Raises: :exc:`FormatError` if instance does not conform to ``format`` """ if format not in self.checkers: return func, raises = self.checkers[format] result, cause = None, None try: result = func(instance) except raises as e: cause = e if not result: raise FormatError( "%r is not a %r" % (instance, format), cause=cause, )
Example #20
Source File: _format.py From misp42splunk with GNU Lesser General Public License v3.0 | 5 votes |
def conforms(self, instance, format): """ Check whether the instance conforms to the given format. Arguments: instance (any primitive type, i.e. str, number, bool): The instance to check format (str): The format that instance should conform to Returns: bool: Whether it conformed """ try: self.check(instance, format) except FormatError: return False else: return True
Example #21
Source File: _format.py From misp42splunk with GNU Lesser General Public License v3.0 | 5 votes |
def check(self, instance, format): """ Check whether the instance conforms to the given format. Arguments: instance (any primitive type, i.e. str, number, bool): The instance to check format (str): The format that instance should conform to Raises: :exc:`FormatError` if instance does not conform to ``format`` """ if format not in self.checkers: return func, raises = self.checkers[format] result, cause = None, None try: result = func(instance) except raises as e: cause = e if not result: raise FormatError( "%r is not a %r" % (instance, format), cause=cause, )
Example #22
Source File: _validators.py From misp42splunk with GNU Lesser General Public License v3.0 | 5 votes |
def format(validator, format, instance, schema): if validator.format_checker is not None: try: validator.format_checker.check(instance, format) except FormatError as error: yield ValidationError(error.message, cause=error.cause)
Example #23
Source File: _format.py From misp42splunk with GNU Lesser General Public License v3.0 | 5 votes |
def conforms(self, instance, format): """ Check whether the instance conforms to the given format. Arguments: instance (any primitive type, i.e. str, number, bool): The instance to check format (str): The format that instance should conform to Returns: bool: Whether it conformed """ try: self.check(instance, format) except FormatError: return False else: return True