本文整理汇总了Python中jsonschema.draft4_format_checker方法的典型用法代码示例。如果您正苦于以下问题:Python jsonschema.draft4_format_checker方法的具体用法?Python jsonschema.draft4_format_checker怎么用?Python jsonschema.draft4_format_checker使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类jsonschema
的用法示例。
在下文中一共展示了jsonschema.draft4_format_checker方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: getValidator
# 需要导入模块: import jsonschema [as 别名]
# 或者: from jsonschema import draft4_format_checker [as 别名]
def getValidator(schema, schema_store):
"""
Get a L{jsonschema} validator for C{schema}.
@param schema: The JSON Schema to validate against.
@type schema: L{dict}
@param dict schema_store: A mapping between schema paths
(e.g. ``b/v1/types.json``) and the JSON schema structure.
"""
# The base_uri here isn't correct for the schema,
# but does give proper relative paths.
resolver = LocalRefResolver(
base_uri=b'',
referrer=schema, store=schema_store)
return validator_for(schema)(
schema, resolver=resolver, format_checker=draft4_format_checker)
示例2: validate
# 需要导入模块: import jsonschema [as 别名]
# 或者: from jsonschema import draft4_format_checker [as 别名]
def validate(data, schema):
"""Validate data against a JSON schema.
This is a helper function used by :py:class:`JsonSchemaValidationMixin`
to validate data against a JSON schema. If validation fails this function
will raise a :py:class:`pyramid.httpexceptions.HTTPBadRequest` exception
describing the validation error.
:raises pyramid.httpexceptions.HTTPBadRequest: if validation fails this
exception is raised to abort any further processing.
"""
try:
jsonschema.validate(data, schema,
format_checker=jsonschema.draft4_format_checker)
except jsonschema.ValidationError as e:
error = {
'.'.join(str(p) for p in e.path): e.message
}
response = JSONValidationError(json=error)
response.validation_error = e
raise response
示例3: validate
# 需要导入模块: import jsonschema [as 别名]
# 或者: from jsonschema import draft4_format_checker [as 别名]
def validate(self):
try:
Draft4Validator(self.schema, format_checker=draft4_format_checker).validate(
self.config
)
except JsonSchemaError as e:
raise ValidationError(e)
示例4: is_input_valid
# 需要导入模块: import jsonschema [as 别名]
# 或者: from jsonschema import draft4_format_checker [as 别名]
def is_input_valid(self, request, pipeline_config, section):
config = pipeline_config.get(section, {})
try:
if (section in request):
input_validator = jsonschema.Draft4Validator(
schema=config, format_checker=jsonschema.draft4_format_checker)
input_validator.validate(request.get(section, {}))
self.logger.debug(
"{} Validation successful".format(section))
return True
except Exception as error:
self.logger.debug(
"Validation error in request section {}, error: {}".format(section, error))
return False