comicbox.validate.spec

source module comicbox.validate.spec

Deferred validator declarations.

Format registrations name their schema validator with a ValidatorSpec instead of constructing one. Construction is not cheap: it imports xmlschema or jsonschema and then compiles an XSD 1.1 or JSON Schema document. Doing that eagerly put ~200ms of schema compilation into every import comicbox.formats — paid by every read, write, and CLI run — while the only consumer is the opt-in --validate path in comicbox.box.validate.

Naming a validator here is pure data. Nothing heavier than comicbox itself is imported until build_validator() is called.

Classes

  • ValidatorType — Schema languages comicbox validates metadata against.

  • ValidatorSpec — A schema language and the schema file to validate against.

Functions

source enum ValidatorType()

Bases : Enum

Schema languages comicbox validates metadata against.

Attributes

  • XML

  • JSON

  • YAML

source dataclass ValidatorSpec(validator_type: ValidatorType, schema_path: str)

A schema language and the schema file to validate against.

Frozen and hashable so build_validator() can memoize on it: the three comicbox-native registrations name the same schema file, and without the memo every validate_source() call would recompile.

source build_validator(spec: ValidatorSpec) → BaseValidator

Construct (and compile) the validator a spec names.

Raises

  • NotImplementedError

source validation_failure_exceptions() → tuple[type[Exception], …]

Get the exceptions a validator raises for invalid data.

Deferred for the same reason the validators are: importing these names at module scope pulls in all of xmlschema and jsonschema even when nothing validates.