gavo.base.common module

Common code for DaCHS’s base package.

exception gavo.base.common.Ignore[source]

Bases: ExecutiveAction

An executive action causing an element to be not adopted by its parent.

Raise this in – typically – onElementComplete if the element just built goes somewhere else but into its parent structure (or is somehow benignly unusable). Classic use case: Active Tags.

class gavo.base.common.Parser[source]

Bases: object

A mixin for a structure you can feed events to.

The class mixing thing in must define methods start_, end_, and value_, each accepting a parse context (a base.RDParseContext instance), the name of an element or attribute, and a value (which is an attribute of dicts in the case of start, and a string in the case of value.

They all must return either None or the next parser; start_ may also return a string, which then names the attribute the next value is for.

end_(ctx: None, name: str, value: Optional[Union[Dict[str, str], str]]) Optional[Parser][source]
feedEvent(ctx: None, type: ParserEventName, name: str, value: Optional[Union[Dict[str, str], str]]) Optional[Union[Parser, str]][source]
start_(ctx: None, name: str, value: Optional[Union[Dict[str, str], str]]) Optional[Union[Parser, str]][source]
value_(ctx: None, name: str, value: Optional[Union[Dict[str, str], str]]) Optional[Parser][source]
class gavo.base.common.ParserEvent(*args)[source]

Bases: tuple

a tuple consists of an event type (a ParserEventType) the name and value from common.Parser, and the position object.

We probably should use a namedtuple here one day and actually check we get what we need, but for now, this is only to acquiesce the type checker.

gavo.base.common.ParserEventType

alias of ParserEventName

exception gavo.base.common.Replace(newOb: None, newName: Optional[str] = None)[source]

Bases: ExecutiveAction

An executive action replacing the current child with the Exception’s argument.

Use this sparingly. I’d like to get rid of it.

class gavo.base.common.StructCallbacks[source]

Bases: object

A class terminating super() calls for the structure callbacks.

Structs, when finished, call completeElement(ctx), validate(), and onElementComplete() in sequence. All these need to up-call. This mixin provides non-upcalling implementations of these methods, and it needs to be present in mixins for structure.

This will only work properly if self actually is a struct, as we rely on the presence of name_ attributes in case of prematurely terminated method resolution.

completeElement(ctx: None) None[source]
name_: Type[<Undefined>]] = '(StructCallbacks terminator)'
onElementComplete() None[source]
setParent(parent: Any) None[source]
validate() None[source]
class gavo.base.common.StructParseDebugMixin[source]

Bases: object

put this before Parser in the parent class list of a struct, and you’ll see the events coming in to your parser.

feedEvent(ctx: None, type: ParserEventName, name: str, value: Optional[Union[Dict[str, str], str]]) Optional[Self][source]