odata_query.visitor module

class odata_query.visitor.NodeTransformer[source]

Bases: NodeVisitor

A subclass of NodeVisitor that allows replacing of nodes in the AST as it passes over it. The visitor methods should return instances of _Node that replace the passed node.

generic_visit(node: _Node) _Node[source]

Visits all fields on node recursively. Called if no explicit visitor method exists for a node.

class odata_query.visitor.NodeVisitor[source]

Bases: object

Base class for visitors that walk the AST and calls a visitor method for every node found. This method may return a value which is forwarded by the visit() method.

This class is meant to be subclassed, with the subclass adding visitor methods. By default the visitor methods for the nodes are named 'visit_' + class name of the node (e.g. visit_Identifier(self, identifier)). If no visitor method exists for a node, the generic_visit() visitor is used instead.

generic_visit(node: _Node)[source]

Visits all fields on node recursively. Called if no explicit visitor method exists for a node.

visit(node: _Node) Any[source]

Looks for an explicit node visiting method on self, otherwise calls generic_visit().

Returns:

Whatever the called method returned. The user is free to choose what the NodeVisitor should return.

odata_query.visitor.iter_dataclass_fields(node: _Node) Iterator[Tuple[str, Any]][source]

Loops over all fields of the given node, yielding the field’s name and the current value.

Yields:

Tuples of (fieldname, value) for each field in node._fields.