gavo.utils.autonode module

Autonodes are stripped-down versions of the full DaCHS structures.

The idea is to have “managed attributes light” with automatic constructors. The Autonodes are used when building something like abstract syntax trees in STC or ADQL.

class gavo.utils.autonode.AutoNode[source]

Bases: object

An AutoNode.

AutoNodes are explained in AutoNode’s metaclass, AutoNodeType.

A noteworthy method is change – pass in new attribute values to create a new instance with the original attribute values except for those passed to change. This will only work if all non-autoattribute attributes of the class are set in _setupNode.


returns a shallow copy of self with constructor arguments in kwargs changed.

classmethod cloneFrom(other, **kwargs) AutoNode[source]

returns a shallow clone of other.

other should be of the same class or a superclass.

iterAttributes(skipEmpty: bool = False)[source]

yields pairs of attributeName, attributeValue for this node.

iterChildren(skipEmpty: bool = False)[source]

yields pairs of attributeName, attributeValue for this node.

This will look into sequences, so multiple occurrences of an attributeName are possible. Only nodes are returned.


iterates the tree preorder.

Only AutoNodes are returned, not python values.

class gavo.utils.autonode.AutoNodeType(name: str, bases: Tuple[type, ...], dict: Dict)[source]

Bases: type

A metaclass for AutoNodes.

The idea here is to define children in a class definition and make sure they are actually present.

AutoNodes are supposed to be immutable; the are defined during construction. Currently, nothing keeps you from changing them afterwards, but that may change.

The classes’ constructor is defined to accept all attributes as arguments (you probably want to use keyword arguments here). It is the constructor that sets up the attributes, so AutoNodes must not have an __init__ method. However, they may define a method _setupNode that is called just before the artificial constructor returns.

To define the attributes of the class, add _a_<attname> attributes giving a default to the class. The default should normally be either None for 1:1 or 1:0 relations or an empty tuple for 1:n relations. The defaults must return a repr that constructs them, since we create a source fragment.