Building ASTs from STC-X trees.

The idea here is run buildTree on an ElementTree of the STC-X input.

buildTree has a dictionary mapping element names to handlers. This dictionary is built with a modicum of metaprogramming within _getHandlers.

Each handler receives the ElementTree node it is to operate on, the current buildArgs (i.e., a dictionary containing for building instances collected by buildTree while walking the tree), and a context object.

Handlers yield keyword-value pairs that are added to the buildArgs. If the value is a tuple or list, it will be appended to the current value for that keyword, otherwise it will fill this keyword. Overwrites are not allowed.


Bases: ContextActions

Context actions for Boxes: register a special handler for Size.

boxHandlers = {<QName '{}Size'>: <function _makeKwValueBuilder.<locals>.buildNode>}
start(context, node)[source]
stop(context, node)[source]

Bases: object

A specification of context actions for certain elements.

You will want to override both start and stop. The methods should not change node.

start(context, node)[source]
stop(context, node)[source]

Bases: ContextActions

Actions for containers of coordinates.

The actions push and pop the system ids of the coordinate containers so leaves can build their frame proxies from them.

If none are present, None is pushed, which is to be understood as “use any ol’ AstroCoordSystem you can find”.

start(context, node)[source]
stop(context, node)[source]
class, idref=None, ucd=None, useAttr=None)[source]

Bases: ASTNode

A stand-in for a coordinate system during parsing.

We do this to not depend on ids being located before positions. STC should have that in general, but let’s be defensive here.


Bases: object

A sentinel class to tell the id resolver to use the sibling AstroCoordSys element.[source]
class, activeTags, vecTags={<QName '{}AllSky'>: 2, <QName '{}Box'>: 2, <QName '{}Box2'>: 2, <QName '{}Circle'>: 2, <QName '{}Circle2'>: 2, <QName '{}Convex'>: 3, <QName '{}Difference'>: 2, <QName '{}Ellipse'>: 2, <QName '{}Error2'>: 2, <QName '{}Error3'>: 3, <QName '{}HiLimit2Vec'>: 2, <QName '{}HiLimit3Vec'>: 3, <QName '{}Intersection'>: 2, <QName '{}LoLimit2Vec'>: 2, <QName '{}LoLimit3Vec'>: 3, <QName '{}Negation'>: 2, <QName '{}PixSize2'>: 2, <QName '{}PixSize3'>: 3, <QName '{}Polygon'>: 2, <QName '{}Polygon2'>: 2, <QName '{}Position2D'>: 2, <QName '{}Position2VecInterval'>: 2, <QName '{}Position3D'>: 3, <QName '{}Position3VecInterval'>: 3, <QName '{}PositionInterval'>: 2, <QName '{}Resolution2'>: 2, <QName '{}Resolution3'>: 3, <QName '{}Size2'>: 2, <QName '{}Size3'>: 3, <QName '{}Union'>: 2, <QName '{}Value2'>: 2, <QName '{}Value3'>: 3, <QName '{}Velocity2D'>: 2, <QName '{}Velocity2VecInterval'>: 2, <QName '{}Velocity3D'>: 3, <QName '{}Velocity3VecInterval'>: 3}, **kwargs)[source]

Bases: object

A parse context containing handlers, stacks, etc.

A special feature is that there are “context-active” tags. For those the context gets notified by buildTree when their processing is started or ended. We use this to note the active coordinate systems during, e.g., AstroCoords parsing.


returns a builder for the qName elementName, and the expected dimension of child vectors.

If no such handler exists, we return None, None

startTag(node)[source], context)[source]

traverses the ElementTree cst, trying handler functions for each node.

The handler functions are taken from the context.elementHandler dictionary that maps QNames to callables. These callables have the signature handle(STCNode, context) -> iterator, where the iterator returns key-value pairs for inclusion into the argument dictionaries for STCNodes.

Unknown nodes are simply ignored. If you need to bail out on certain nodes, raise explicit exceptions in handlers.

This also manages the expected number of dimensions in vectors by pushing and popping from the context’s dimension stack. The actual wisdom on what elements set which dimensions is kept in the context object as well.[source]

returns a mapping from STC-X names to the number of dimensions child vectors should have.[source]

returns a sequence of pairs (root element, AST) for eTree containing parsed STC-X.[source]

returns a sequence of pairs (root element, AST) for the STC-X specifications in stcxLiteral.[source]

replaces IdProxies in the AST sequence forest with actual references.