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

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

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)[source]

Bases: object

An assertion about the meta content of an object.

You must override the C{check} method.

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}.

class gavo.base.metavalidation.MetaAtomicExistsOnSelf(key)[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)[source]

Bases: MetaAssertion

An assertion that a meta item is present for key in whatever form.

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}.

class gavo.base.metavalidation.MetaIsAtomic(key)[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, failures)[source]

Bases: MetaError

class gavo.base.metavalidation.MetaValidator(model)[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.

validate(metaCarrier)[source]
gavo.base.metavalidation.parseModel(modelDescr)[source]

returns a MetaValidator for a model description.

model descriptions are covered in the module docstring.

gavo.base.metavalidation.validateStructure(aStruct)[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.