当前位置: 首页>>代码示例>>Python>>正文


Python exceptions.FormatError方法代码示例

本文整理汇总了Python中jsonschema.exceptions.FormatError方法的典型用法代码示例。如果您正苦于以下问题:Python exceptions.FormatError方法的具体用法?Python exceptions.FormatError怎么用?Python exceptions.FormatError使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在jsonschema.exceptions的用法示例。


在下文中一共展示了exceptions.FormatError方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: check

# 需要导入模块: from jsonschema import exceptions [as 别名]
# 或者: from jsonschema.exceptions import FormatError [as 别名]
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) 
开发者ID:openstack,项目名称:masakari,代码行数:27,代码来源:validators.py

示例2: check

# 需要导入模块: from jsonschema import exceptions [as 别名]
# 或者: from jsonschema.exceptions import FormatError [as 别名]
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) 
开发者ID:openstack,项目名称:tacker,代码行数:27,代码来源:validators.py

示例3: check

# 需要导入模块: from jsonschema import exceptions [as 别名]
# 或者: from jsonschema.exceptions import FormatError [as 别名]
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,
            ) 
开发者ID:splunk,项目名称:SA-ctf_scoreboard,代码行数:26,代码来源:_format.py

示例4: conforms

# 需要导入模块: from jsonschema import exceptions [as 别名]
# 或者: from jsonschema.exceptions import FormatError [as 别名]
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 
开发者ID:splunk,项目名称:SA-ctf_scoreboard,代码行数:19,代码来源:_format.py

示例5: check

# 需要导入模块: from jsonschema import exceptions [as 别名]
# 或者: from jsonschema.exceptions import FormatError [as 别名]
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,
            ) 
开发者ID:remg427,项目名称:misp42splunk,代码行数:36,代码来源:_format.py

示例6: conforms

# 需要导入模块: from jsonschema import exceptions [as 别名]
# 或者: from jsonschema.exceptions import FormatError [as 别名]
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 
开发者ID:remg427,项目名称:misp42splunk,代码行数:28,代码来源:_format.py

示例7: format

# 需要导入模块: from jsonschema import exceptions [as 别名]
# 或者: from jsonschema.exceptions import FormatError [as 别名]
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) 
开发者ID:remg427,项目名称:misp42splunk,代码行数:8,代码来源:_validators.py

示例8: test_format_checker_failed

# 需要导入模块: from jsonschema import exceptions [as 别名]
# 或者: from jsonschema.exceptions import FormatError [as 别名]
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()) 
开发者ID:openstack,项目名称:masakari,代码行数:11,代码来源:test_api_validation.py

示例9: test_format_checker_failed_with_non_string

# 需要导入模块: from jsonschema import exceptions [as 别名]
# 或者: from jsonschema.exceptions import FormatError [as 别名]
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()) 
开发者ID:openstack,项目名称:masakari,代码行数:14,代码来源:test_api_validation.py

示例10: validate_json

# 需要导入模块: from jsonschema import exceptions [as 别名]
# 或者: from jsonschema.exceptions import FormatError [as 别名]
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 
开发者ID:airshipit,项目名称:shipyard,代码行数:43,代码来源:json_schemas.py


注:本文中的jsonschema.exceptions.FormatError方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。