gavo.base.metavalidation module¶
Meta information validation.
The idea is that you define certain assertions about the meta information of a given object type. Defined assertions are
MetaExists – a key is present
MetaIsAtomic – a key is present and a “leaf”, i.e., has a single value
- MetaAtomicExistsOnSelf – a key is present even without meta inheritance,
and has a single value
MetaValueInVocabulary – the value of a meta item is in an IVOA vocabulary.
Validators are usually built using model descriptions. These are enumerations of meta keys, separated by commas, with an optional code in parenteses. Whitespace is ignored. Codes allowed in parens are:
empty (default): plain existence
!: atomic existence on self
1: atomic existence
?: optional (this only makes sense with other constraints, as any meta value is allowed on anything
voc:vocname: all values must come from the IVOA vocabulary vocname.
Multiple assertions are separated by whitespace.
An example for a valid model description: “publisher.name,creator.email(), identifier (!), dateUpdated(1)”
These model descriptions can come in metaModel attributes of structures. If they are, you can use the validateStructure function below to validate an entire structure tree.
- class gavo.base.metavalidation.MetaAssertion(key: str)[source]¶
Bases:
object
An assertion about the meta content of an object.
You must override the C{check} method.
- class gavo.base.metavalidation.MetaAtomicExistsOnSelf(key: str)[source]¶
Bases:
MetaIsAtomic
An assertion that a meta item is present and unique for key on metaCarrier itself.
- propagate = False¶
- class gavo.base.metavalidation.MetaExists(key: str)[source]¶
Bases:
MetaAssertion
An assertion that a meta item is present for key in whatever form.
- class gavo.base.metavalidation.MetaIsAtomic(key: str)[source]¶
Bases:
MetaAssertion
An assertion that a meta item is present and contains a single value only.
- check(metaCarrier)[source]¶
returns None if the assertion is true, a user-displayable string of what failed otherwise.
This must be overridden in derived classes. @param metaCarrier: an object mixing in L{MetaMixin}.
- propagate = True¶
- exception gavo.base.metavalidation.MetaValidationError(carrier: MetaMixin, failures: Sequence[str])[source]¶
Bases:
MetaError
- class gavo.base.metavalidation.MetaValidator(model: Sequence[MetaAssertion])[source]¶
Bases:
object
A metadata model that can verify objects of compliance.
The model is quite simple: it’s a sequence of MetaAssertions. The validate(metaCarrier) -> None method raises a MetaNotValid exception with all failed assertions in its failedAssertions attribute.
- class gavo.base.metavalidation.MetaValueInVocabulary(key: str, vocName: str)[source]¶
Bases:
MetaAssertion
- class gavo.base.metavalidation.NullAssertion(key: str)[source]¶
Bases:
MetaAssertion
An assertion that always succeeds.
This is for implementation convenience.
- gavo.base.metavalidation.parseModel(modelDescr: str) ParserElement [source]¶
returns a MetaValidator for a model description.
model descriptions are covered in the module docstring.
- gavo.base.metavalidation.validateStructure(aStruct: None) None [source]¶
does a meta validation for a base.Structure.
This works by traversing the children of the structure, looking for nodes with a metaModel attribute. For all these, a validation is carried out. The first node failing the validation determines the return value.
The function raises a MetaValidationError if aStruct is invalid.