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.
ValidatorSpec dataclass ¶
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 code in comicbox/validate/spec.py
33 34 35 36 37 38 39 40 41 42 43 44 | |
ValidatorType ¶
Bases: Enum
Schema languages comicbox validates metadata against.
Source code in comicbox/validate/spec.py
25 26 27 28 29 30 | |
build_validator(spec) cached ¶
Construct (and compile) the validator a spec names.
Source code in comicbox/validate/spec.py
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 | |
validation_failure_exceptions() cached ¶
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.
Source code in comicbox/validate/spec.py
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 | |