ocfl.InventoryValidator
OCFL Inventory Validator.
Code to validate the Python representation of an OCFL Inventory as read with json.load(). Does not examine anything in storage and designed to be used on inventories alone or before any validation of files on storage.
Example
>>> import ocfl
>>> import json
>>> with open("fixtures/1.1/good-objects/spec-ex-full/inventory.json") as fh:
... inv = json.load(fh)
...
>>> iv = ocfl.InventoryValidator()
>>> iv.validate(inv)
True
>>> iv.spec_version
"1.1"
>>> with open("fixtures/1.1/bad-objects/E025_wrong_digest_algorithm/inventory.json") as fh:
... inv = json.load(fh)
...
>>> iv = ocfl.InventoryValidator()
>>> iv.validate(inv)
False
>>> str(iv.log)
"[E025a] OCFL Object ??? inventory `digestAlgorithm` attribute not an allowed digest type (got 'md5') (see https://ocfl.io/1.1/spec/#E025)"
- class ocfl.InventoryValidator(*, log=None, where='???', lax_digests=False, default_spec_version='1.1')
Class for OCFL Inventory Validator.
- __init__(*, log=None, where='???', lax_digests=False, default_spec_version='1.1')
Initialize OCFL Inventory Validator.
It is expected that a new InventoryValidator object be created for each validation because object state records both the status of validation and some extracted properties. The exception is the method validate_as_prior_version() which validates a second inventory as a prior version of this (root) inventory.
- Keyword Arguments:
log – a ValidationLogger instance to log errors and warnings encountered during validation. If not set (None, the default) then a new instance with logging defaults is created.
where – a string used in log messages to indicate where the issues occurs. Is it the root inventory or a specific version? Defaults to “???”.
lax_digests – True to allow any digest to be used for content addressing, as opposed to only those allowed by the specification.
default_spec_version – string (defaults to ocfl.constants.DEFAULT_SPEC_VERSION) indicating the specification version to assume if it is not set.
- validate(inventory, force_spec_version=None)
Validate a given inventory.
Normally, code will look at the type value to determine the specification version against which to validate the inventory. In the case that there is no type value or it isn”t valid, then other tests will be based on the specification version given in self.default_spec_version.
If force_spec_version is set then the specified specification version will be used for validation.
Returns True on success (no errors), False otherwise. Details of the validation in instance variables and the log object.
- validate_as_prior_version(prior)
Check that prior is a valid prior version of the current inventory object.
The input variable prior is also expected to be an InventoryValidator object and both self and prior inventories are assumed to have been checked for internal consistency.
Returns True on success (no errors), False otherwise. Details of the validation in instance variables and the log object.