Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def __init__(self, schema, validator_class=Draft4Validator):
self.validator = validator_class(schema)
def validate(self, obj):
report = ValidationReport()
if not self.validator.is_valid(obj):
for v in self.validator.iter_errors(obj):
report.add_error("[%s] %s" % ('.'.join(str(vv) for vv in v.path), v.message))
return report
#
# -------------------------------------------------
#
class ParameterValidator(JsonValidator):
def __init__(self, ocrd_tool):
# TODO grep required properties
required = []
p = ocrd_tool['parameters']
for n in p:
if 'required' in p[n]:
if p[n]['required']:
required.append(n)
del(p[n]['required'])
super(ParameterValidator, self).__init__({
"type": "object",
"required": required,
"properties": p
}, DefaultValidatingDraft4Validator)
def validate_json(obj, schema):
if isinstance(obj, str):
obj = json.loads(obj)
return JsonValidator(schema).validate(obj)
def validate_json(obj, schema=OCRD_TOOL_SCHEMA):
return JsonValidator.validate_json(obj, schema)
if 'required' in p[n]:
if p[n]['required']:
required.append(n)
del(p[n]['required'])
super(ParameterValidator, self).__init__({
"type": "object",
"required": required,
"properties": p
}, DefaultValidatingDraft4Validator)
#
# -------------------------------------------------
#
class OcrdToolValidator(JsonValidator):
@staticmethod
def validate_json(obj, schema=OCRD_TOOL_SCHEMA):
return JsonValidator.validate_json(obj, schema)
#
# -------------------------------------------------
#
class WorkspaceValidator(object):
"""
Validates an OCR-D/METS workspace against the specs.
Args:
resolver (:class:`Resolver`) : Instance of a resolver
mets_url (string) : URL of the METS file