本文整理汇总了Python中jsonschema.validators.validator_for方法的典型用法代码示例。如果您正苦于以下问题:Python validators.validator_for方法的具体用法?Python validators.validator_for怎么用?Python validators.validator_for使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类jsonschema.validators
的用法示例。
在下文中一共展示了validators.validator_for方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: getValidator
# 需要导入模块: from jsonschema import validators [as 别名]
# 或者: from jsonschema.validators import validator_for [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: full_validate
# 需要导入模块: from jsonschema import validators [as 别名]
# 或者: from jsonschema.validators import validator_for [as 别名]
def full_validate(
schema: RawSchema, raw_items: RawItems, keys: pd.Index
) -> Dict[str, set]:
"""This function uses jsonschema validator which returns all found error per item.
See `fast_validate()` for arguments descriptions.
"""
errors: DefaultDict = defaultdict(set)
validator = validators.validator_for(schema)(schema)
validator.format_checker = FormatChecker()
for i, raw_item in enumerate(tqdm(raw_items, desc="JSON Schema Validation")):
raw_item.pop("_type", None)
raw_item.pop("_key", None)
for e in validator.iter_errors(raw_item):
error = format_validation_message(
e.message, e.path, e.schema_path, e.validator
)
errors[error].add(keys[i])
return dict(errors)
示例3: parse_args
# 需要导入模块: from jsonschema import validators [as 别名]
# 或者: from jsonschema.validators import validator_for [as 别名]
def parse_args(args):
arguments = vars(parser.parse_args(args=args or ["--help"]))
if arguments["validator"] is None:
arguments["validator"] = validator_for(arguments["schema"])
return arguments
示例4: _validate
# 需要导入模块: from jsonschema import validators [as 别名]
# 或者: from jsonschema.validators import validator_for [as 别名]
def _validate(self, data, strict=False):
validator_cls = validator_for(self._schema)
validator = validator_cls(schema=self._schema, format_checker=format_checker)
errors = validator.iter_errors(data)
for error in errors:
absolute_path = list(error.absolute_path)
required_match = REQUIRED_RE.search(error.message)
if required_match:
absolute_path.append(required_match.group(1))
field_name = ".".join([str(p) for p in absolute_path])
self._add_errors({field_name: [error.message]})
示例5: validate
# 需要导入模块: from jsonschema import validators [as 别名]
# 或者: from jsonschema.validators import validator_for [as 别名]
def validate(parsed_data):
# Load the schema
schema_file = open(RULES_FILE, 'r')
schema_data = json.load(schema_file)
# Validate the file
validator = validator_for(schema_data)
errors = validator(schema=schema_data).iter_errors(parsed_data)
# Extract error messages and return
messages = []
for error in errors:
messages.append('---- ISSUE: ' + error.schema['title'] + '; ' + error.message)
return messages