gavo.rscdef.procdef module

Basic handling for embedded procedures.

class gavo.rscdef.procdef.AliasableRDParameter(parent, **kwargs)[source]

Bases: RDParameter

A base class for RD parameter definitions that support aliases.

attrSeq = [<gavo.base.attrdef.UnicodeAttribute object>, <gavo.base.attrdef.NWUnicodeAttribute object>, <gavo.base.structure.DataContent object>, <gavo.base.parsecontext.IdAttribute object>, <gavo.base.attrdef.BooleanAttribute object>, <gavo.base.attrdef.UnicodeAttribute object>]
completedCallbacks = []
managedAttrs = {'alias': <gavo.base.attrdef.UnicodeAttribute object>, 'content_': <gavo.base.structure.DataContent object>, 'description': <gavo.base.attrdef.NWUnicodeAttribute object>, 'id': <gavo.base.parsecontext.IdAttribute object>, 'key': <gavo.base.attrdef.UnicodeAttribute object>, 'late': <gavo.base.attrdef.BooleanAttribute object>, 'name': <gavo.base.attrdef.UnicodeAttribute object>}
class gavo.rscdef.procdef.Binding(parent, **kwargs)[source]

Bases: ProcPar

A binding of a procedure definition parameter to a concrete value.

The value to set is contained in the binding body in the form of a python expression. The body must not be empty.

attrSeq = [<gavo.base.attrdef.UnicodeAttribute object>, <gavo.base.attrdef.NWUnicodeAttribute object>, <gavo.base.structure.DataContent object>, <gavo.base.parsecontext.IdAttribute object>, <gavo.base.attrdef.BooleanAttribute object>, <gavo.base.attrdef.UnicodeAttribute object>]
completedCallbacks = []
managedAttrs = {'alias': <gavo.base.attrdef.UnicodeAttribute object>, 'content_': <gavo.base.structure.DataContent object>, 'description': <gavo.base.attrdef.NWUnicodeAttribute object>, 'id': <gavo.base.parsecontext.IdAttribute object>, 'key': <gavo.base.attrdef.UnicodeAttribute object>, 'late': <gavo.base.attrdef.BooleanAttribute object>, 'name': <gavo.base.attrdef.UnicodeAttribute object>}
name_ = 'bind'
validate()[source]
class gavo.rscdef.procdef.ProcApp(parent, **kwargs)[source]

Bases: ProcDef

An abstract base for procedure applications.

Deriving classes need to provide:

  • a requiredType attribute specifying what ProcDefs can be applied.

  • a formalArgs attribute containing a (python) formal argument list

  • of course, a name_ for XML purposes.

They can, in addition, give a class attribute additionalNamesForProcs, which is a dictionary that is joined into the global namespace during procedure compilation.

additionalNamesForProcs = {}
attrSeq = [<gavo.base.complexattrs.StructListAttribute object>, <gavo.base.attrdef.UnicodeAttribute object>, <gavo.base.attrdef.UnicodeAttribute object>, <gavo.base.attrdef.UnicodeAttribute object>, <gavo.base.parsecontext.IdAttribute object>, <gavo.base.attrdef.UnicodeAttribute object>, <gavo.base.parsecontext.OriginalAttribute object>, <gavo.base.parsecontext.ReferenceAttribute object>, <gavo.base.complexattrs.StructListAttribute object>, <gavo.base.attrdef.EnumeratedUnicodeAttribute object>]
breakCircles()[source]

removes the parent attributes from all child structures recursively.

The struct will probably be broken after this, but this is sometimes necessary to help the python garbage collector.

In case you’re asking: parent cannot be a weak reference with the current parse architecture, as it usually is the only reference to the embedding object. Yes, we should probably change that.

compile(parent=None)[source]

returns a callable for this procedure application.

You can pass a different parent; it will then be used to expand macros. If you do not give it, the embedding structure will be used.

completeElement(ctx)[source]
completedCallbacks = []
getBodySetupCode(boundNames)[source]
getFuncCode()[source]

returns a function definition for this proc application.

This includes bindings of late parameters.

Locally defined code overrides code defined in a procDef.

getLateSetupCode(boundNames)[source]
getParSetupCode(boundNames)[source]
getSetupCode()[source]
getSetupPars()[source]

returns the setup parameters for the proc app, where procDef parameters may be overridden by self’s parameters.

managedAttrs = {'bind': <gavo.base.complexattrs.StructListAttribute object>, 'bindings': <gavo.base.complexattrs.StructListAttribute object>, 'code': <gavo.base.attrdef.UnicodeAttribute object>, 'deprecated': <gavo.base.attrdef.UnicodeAttribute object>, 'doc': <gavo.base.attrdef.UnicodeAttribute object>, 'id': <gavo.base.parsecontext.IdAttribute object>, 'name': <gavo.base.attrdef.UnicodeAttribute object>, 'original': <gavo.base.parsecontext.OriginalAttribute object>, 'procDef': <gavo.base.parsecontext.ReferenceAttribute object>, 'setup': <gavo.base.complexattrs.StructListAttribute object>, 'setups': <gavo.base.complexattrs.StructListAttribute object>, 'type': <gavo.base.attrdef.EnumeratedUnicodeAttribute object>}
onElementComplete()[source]
requiredType = None
validate()[source]
class gavo.rscdef.procdef.ProcDef(parent, **kwargs)[source]

Bases: Structure, RestrictionMixin

An embedded procedure.

Embedded procedures are python code fragments with some interface defined by their type. They can occur at various places (which is called procedure application generically), e.g., as row generators in grammars, as apply-s in rowmakers, or as SQL phrase makers in condDescs.

They consist of the actual actual code and, optionally, definitions like the namespace setup, configuration parameters, or a documentation.

The procedure applications compile into python functions with special global namespaces. The signatures of the functions are determined by the type attribute.

ProcDefs are referred to by procedure applications using their id.

attrSeq = [<gavo.base.attrdef.UnicodeAttribute object>, <gavo.base.attrdef.UnicodeAttribute object>, <gavo.base.attrdef.UnicodeAttribute object>, <gavo.base.parsecontext.IdAttribute object>, <gavo.base.parsecontext.OriginalAttribute object>, <gavo.base.complexattrs.StructListAttribute object>, <gavo.base.attrdef.EnumeratedUnicodeAttribute object>]
completedCallbacks = []
getBodySetupCode(boundNames)[source]
getCode()[source]

returns the body code indented with two spaces.

getLateSetupCode(boundNames)[source]
getParSetupCode(boundNames)[source]
getSetupPars()[source]

returns all parameters used by setup items, where lexically later items override earlier items of the same name.

managedAttrs = {'code': <gavo.base.attrdef.UnicodeAttribute object>, 'deprecated': <gavo.base.attrdef.UnicodeAttribute object>, 'doc': <gavo.base.attrdef.UnicodeAttribute object>, 'id': <gavo.base.parsecontext.IdAttribute object>, 'original': <gavo.base.parsecontext.OriginalAttribute object>, 'setup': <gavo.base.complexattrs.StructListAttribute object>, 'setups': <gavo.base.complexattrs.StructListAttribute object>, 'type': <gavo.base.attrdef.EnumeratedUnicodeAttribute object>}
name_ = 'procDef'
class gavo.rscdef.procdef.ProcPar(parent, **kwargs)[source]

Bases: AliasableRDParameter

A parameter of a procedure definition.

Bodies of ProcPars are interpreted as python expressions, in which macros are expanded in the context of the procedure application’s parent. If a body is empty, the parameter has no default and has to be filled by the procedure application.

attrSeq = [<gavo.base.attrdef.UnicodeAttribute object>, <gavo.base.attrdef.NWUnicodeAttribute object>, <gavo.base.structure.DataContent object>, <gavo.base.parsecontext.IdAttribute object>, <gavo.base.attrdef.BooleanAttribute object>, <gavo.base.attrdef.UnicodeAttribute object>]
completedCallbacks = []
managedAttrs = {'alias': <gavo.base.attrdef.UnicodeAttribute object>, 'content_': <gavo.base.structure.DataContent object>, 'description': <gavo.base.attrdef.NWUnicodeAttribute object>, 'id': <gavo.base.parsecontext.IdAttribute object>, 'key': <gavo.base.attrdef.UnicodeAttribute object>, 'late': <gavo.base.attrdef.BooleanAttribute object>, 'name': <gavo.base.attrdef.UnicodeAttribute object>}
name_ = 'par'
validate()[source]
class gavo.rscdef.procdef.ProcSetup(parent, **kwargs)[source]

Bases: Structure

Prescriptions for setting up a namespace for a procedure application.

You can add names to this namespace you using par(ameter)s. If a parameter has no default and an procedure application does not provide them, an error is raised.

You can also add names by providing a code attribute containing a python function body in code. Within, the parameters are available. The procedure application’s parent can be accessed as parent. All names you define in the code are available as globals to the procedure body.

Caution: Macros are expanded within the code; this means you need double backslashes if you want a single backslash in python code.

attrSeq = [<gavo.base.complexattrs.ListOfAtomsAttribute object>, <gavo.base.parsecontext.IdAttribute object>, <gavo.base.attrdef.UnicodeAttribute object>, <gavo.base.parsecontext.OriginalAttribute object>, <gavo.base.complexattrs.StructListAttribute object>]
completedCallbacks = []
getBodyCode()[source]

returns the body code un-indented.

getImportsCode()[source]
getLateCode(bindings)[source]

returns code doing late (in-function) bindings indented with two spaces.

getParCode(bindings)[source]

returns code doing setup bindings un-indented.

managedAttrs = {'code': <gavo.base.complexattrs.ListOfAtomsAttribute object>, 'codeFrags': <gavo.base.complexattrs.ListOfAtomsAttribute object>, 'id': <gavo.base.parsecontext.IdAttribute object>, 'imports': <gavo.base.attrdef.UnicodeAttribute object>, 'original': <gavo.base.parsecontext.OriginalAttribute object>, 'par': <gavo.base.complexattrs.StructListAttribute object>, 'pars': <gavo.base.complexattrs.StructListAttribute object>}
name_ = 'setup'
class gavo.rscdef.procdef.RDParameter(parent, **kwargs)[source]

Bases: Structure

A base class for parameters.

attrSeq = [<gavo.base.attrdef.NWUnicodeAttribute object>, <gavo.base.structure.DataContent object>, <gavo.base.parsecontext.IdAttribute object>, <gavo.base.attrdef.BooleanAttribute object>, <gavo.base.attrdef.UnicodeAttribute object>]
completeElement(ctx)[source]
completedCallbacks = []
isDefaulted()[source]
managedAttrs = {'content_': <gavo.base.structure.DataContent object>, 'description': <gavo.base.attrdef.NWUnicodeAttribute object>, 'id': <gavo.base.parsecontext.IdAttribute object>, 'key': <gavo.base.attrdef.UnicodeAttribute object>, 'late': <gavo.base.attrdef.BooleanAttribute object>, 'name': <gavo.base.attrdef.UnicodeAttribute object>}
validate()[source]
gavo.rscdef.procdef.unionByKey(*sequences)[source]

returns all items in sequences uniqued by the items’ key attributes.

The order of the sequence items is not maintained, but items in later sequences override those in earlier ones.