gavo.svcs.standardcores module¶
Some standard cores for services.
A core receives and “input table” (usually just containing the query parameters in the doc rec) and returns an output thing, usually a table (but see the src package docstring).
- class gavo.svcs.standardcores.CondDesc(parent, **kwargs)[source]¶
Bases:
Structure
A query specification for cores talking to the database.
CondDescs define inputs as a sequence of InputKeys (see `Element InputKey`_). Internally, the values in the InputKeys can be translated to SQL.
- adaptForRenderer(renderer)[source]¶
returns a changed version of self if renderer suggests such a change.
This only happens if buildFrom is non-None. The method must return a “defused” version that has buildFrom None (or self, which will do because core.adaptForRenderer stops adapting if the condDescs are stable).
The adaptors may also raise a Replace exception and return a full CondDesc; this is done, e.g., for spoints for the form renderer, since they need two input keys and a completely modified phrase.
- attrSeq = [<gavo.base.parsecontext.ReferenceAttribute object>, <gavo.base.attrdef.BooleanAttribute object>, <gavo.base.attrdef.UnicodeAttribute object>, <gavo.base.complexattrs.StructAttribute object>, <gavo.base.parsecontext.IdAttribute object>, <gavo.rscdef.common.ColumnListAttribute object>, <gavo.base.attrdef.BooleanAttribute object>, <gavo.base.attrdef.UnicodeAttribute object>, <gavo.base.parsecontext.OriginalAttribute object>, <gavo.base.complexattrs.StructAttribute object>, <gavo.base.attrdef.BooleanAttribute object>, <gavo.base.attrdef.BooleanAttribute object>]¶
- completedCallbacks = []¶
- expand(*args, **kwargs)[source]¶
hands macro expansion requests (from phraseMakers) upwards.
This is to the queried table if the parent has one (i.e., we’re part of a core), or to the RD if not (i.e., we’re defined within an rd).
- inputReceived(inPars, queryMeta)[source]¶
returns True if all inputKeys can be filled from inPars.
As a side effect, inPars will receive defaults form the input keys if there are any.
- property makePhrase¶
- managedAttrs = {'buildFrom': <gavo.base.parsecontext.ReferenceAttribute object>, 'combining': <gavo.base.attrdef.BooleanAttribute object>, 'fixedSQL': <gavo.base.attrdef.UnicodeAttribute object>, 'group': <gavo.base.complexattrs.StructAttribute object>, 'id': <gavo.base.parsecontext.IdAttribute object>, 'inputKey': <gavo.rscdef.common.ColumnListAttribute object>, 'inputKeys': <gavo.rscdef.common.ColumnListAttribute object>, 'inputOptional': <gavo.base.attrdef.BooleanAttribute object>, 'joiner': <gavo.base.attrdef.UnicodeAttribute object>, 'original': <gavo.base.parsecontext.OriginalAttribute object>, 'phraseMaker': <gavo.base.complexattrs.StructAttribute object>, 'required': <gavo.base.attrdef.BooleanAttribute object>, 'silent': <gavo.base.attrdef.BooleanAttribute object>}¶
- property name¶
returns some key for uniqueness of condDescs.
- name_ = 'condDesc'¶
- class gavo.svcs.standardcores.DBCore(parent, **kwargs)[source]¶
Bases:
TableBasedCore
A core performing database queries on one table or view.
DBCores ask the service for the desired output schema and adapt their output. The DBCore’s output table, on the other hand, lists all fields available from the queried table.
- attrSeq = [<gavo.base.complexattrs.StructListAttribute object>, <gavo.base.attrdef.BooleanAttribute object>, <gavo.base.attrdef.UnicodeAttribute object>, <gavo.base.parsecontext.IdAttribute object>, <gavo.base.complexattrs.StructAttribute object>, <gavo.base.attrdef.IntAttribute object>, <gavo.rscdef.common.NamePathAttribute object>, <gavo.base.parsecontext.OriginalAttribute object>, <gavo.base.complexattrs.StructAttribute object>, <gavo.base.complexattrs.PropertyAttribute object>, <gavo.base.parsecontext.ReferenceAttribute object>, <gavo.rscdef.common.RDAttribute object>, <gavo.base.attrdef.UnicodeAttribute object>]¶
- clearProperty(name)¶
- completedCallbacks = []¶
- getFullId()¶
- getProperty(name, default=<Undefined>)¶
- getQueryCols(service, queryMeta)[source]¶
returns the fields we need in the output table.
The normal DbBased core just returns whatever the service wants. Derived cores, e.g., for special protocols, could override this to make sure they have some fields in the result they depend on.
- hasProperty(name)¶
- managedAttrs = {'condDesc': <gavo.base.complexattrs.StructListAttribute object>, 'condDescs': <gavo.base.complexattrs.StructListAttribute object>, 'distinct': <gavo.base.attrdef.BooleanAttribute object>, 'groupBy': <gavo.base.attrdef.UnicodeAttribute object>, 'id': <gavo.base.parsecontext.IdAttribute object>, 'inputTable': <gavo.base.complexattrs.StructAttribute object>, 'limit': <gavo.base.attrdef.IntAttribute object>, 'namePath': <gavo.rscdef.common.NamePathAttribute object>, 'original': <gavo.base.parsecontext.OriginalAttribute object>, 'outputTable': <gavo.base.complexattrs.StructAttribute object>, 'properties': <gavo.base.complexattrs.PropertyAttribute object>, 'property': <gavo.base.complexattrs.PropertyAttribute object>, 'queriedTable': <gavo.base.parsecontext.ReferenceAttribute object>, 'rd': <gavo.rscdef.common.RDAttribute object>, 'sortKey': <gavo.base.attrdef.UnicodeAttribute object>}¶
- name_ = 'dbCore'¶
- property rd¶
- resolveName(context, id)¶
- run(service, inputTable, queryMeta)[source]¶
does the DB query and returns an InMemoryTable containing the result.
- setProperty(name, value)¶
- exception gavo.svcs.standardcores.Error(msg: str = '', hint: Optional[str] = None)[source]¶
Bases:
Error
- class gavo.svcs.standardcores.FancyQueryCore(parent, **kwargs)[source]¶
Bases:
TableBasedCore
,RestrictionMixin
A core executing a pre-specified query with fancy conditions.
Unless you select *, you must define the outputTable here; Weird things will happen if you don’t.
The queriedTable attribute is ignored.
- attrSeq = [<gavo.base.complexattrs.StructListAttribute object>, <gavo.base.parsecontext.IdAttribute object>, <gavo.base.complexattrs.StructAttribute object>, <gavo.rscdef.common.NamePathAttribute object>, <gavo.base.parsecontext.OriginalAttribute object>, <gavo.base.complexattrs.StructAttribute object>, <gavo.base.complexattrs.PropertyAttribute object>, <gavo.base.parsecontext.ReferenceAttribute object>, <gavo.base.attrdef.UnicodeAttribute object>, <gavo.rscdef.common.RDAttribute object>, <gavo.base.attrdef.FloatAttribute object>]¶
- clearProperty(name)¶
- completedCallbacks = []¶
- getFullId()¶
- getProperty(name, default=<Undefined>)¶
- hasProperty(name)¶
- managedAttrs = {'condDesc': <gavo.base.complexattrs.StructListAttribute object>, 'condDescs': <gavo.base.complexattrs.StructListAttribute object>, 'id': <gavo.base.parsecontext.IdAttribute object>, 'inputTable': <gavo.base.complexattrs.StructAttribute object>, 'namePath': <gavo.rscdef.common.NamePathAttribute object>, 'original': <gavo.base.parsecontext.OriginalAttribute object>, 'outputTable': <gavo.base.complexattrs.StructAttribute object>, 'properties': <gavo.base.complexattrs.PropertyAttribute object>, 'property': <gavo.base.complexattrs.PropertyAttribute object>, 'queriedTable': <gavo.base.parsecontext.ReferenceAttribute object>, 'query': <gavo.base.attrdef.UnicodeAttribute object>, 'rd': <gavo.rscdef.common.RDAttribute object>, 'timeout': <gavo.base.attrdef.FloatAttribute object>}¶
- name_ = 'fancyQueryCore'¶
- property rd¶
- resolveName(context, id)¶
- setProperty(name, value)¶
- class gavo.svcs.standardcores.FixedQueryCore(parent, **kwargs)[source]¶
Bases:
Core
,RestrictionMixin
A core executing a predefined query.
This usually is not what you want, unless you want to expose the current results of a specific query, e.g., for log or event data.
- attrSeq = [<gavo.base.parsecontext.IdAttribute object>, <gavo.base.complexattrs.StructAttribute object>, <gavo.base.parsecontext.OriginalAttribute object>, <gavo.base.complexattrs.StructAttribute object>, <gavo.base.complexattrs.PropertyAttribute object>, <gavo.base.attrdef.UnicodeAttribute object>, <gavo.rscdef.common.RDAttribute object>, <gavo.base.attrdef.FloatAttribute object>, <gavo.base.attrdef.BooleanAttribute object>]¶
- clearProperty(name)¶
- completedCallbacks = []¶
- getFullId()¶
- getProperty(name, default=<Undefined>)¶
- hasProperty(name)¶
- managedAttrs = {'id': <gavo.base.parsecontext.IdAttribute object>, 'inputTable': <gavo.base.complexattrs.StructAttribute object>, 'original': <gavo.base.parsecontext.OriginalAttribute object>, 'outputTable': <gavo.base.complexattrs.StructAttribute object>, 'properties': <gavo.base.complexattrs.PropertyAttribute object>, 'property': <gavo.base.complexattrs.PropertyAttribute object>, 'query': <gavo.base.attrdef.UnicodeAttribute object>, 'rd': <gavo.rscdef.common.RDAttribute object>, 'timeout': <gavo.base.attrdef.FloatAttribute object>, 'writable': <gavo.base.attrdef.BooleanAttribute object>}¶
- name_ = 'fixedQueryCore'¶
- property rd¶
- setProperty(name, value)¶
- class gavo.svcs.standardcores.NullCore(parent, **kwargs)[source]¶
Bases:
Core
A core always returning None.
This core will not work with the common renderers. It is really intended to go with coreless services (i.e. those in which the renderer computes everything itself and never calls service.runX). As an example, the external renderer could go with this.
- attrSeq = [<gavo.base.parsecontext.IdAttribute object>, <gavo.base.complexattrs.StructAttribute object>, <gavo.base.parsecontext.OriginalAttribute object>, <gavo.base.complexattrs.StructAttribute object>, <gavo.base.complexattrs.PropertyAttribute object>, <gavo.rscdef.common.RDAttribute object>]¶
- clearProperty(name)¶
- completedCallbacks = []¶
- getFullId()¶
- getProperty(name, default=<Undefined>)¶
- hasProperty(name)¶
- inputTableXML = '<inputTable/>'¶
- managedAttrs = {'id': <gavo.base.parsecontext.IdAttribute object>, 'inputTable': <gavo.base.complexattrs.StructAttribute object>, 'original': <gavo.base.parsecontext.OriginalAttribute object>, 'outputTable': <gavo.base.complexattrs.StructAttribute object>, 'properties': <gavo.base.complexattrs.PropertyAttribute object>, 'property': <gavo.base.complexattrs.PropertyAttribute object>, 'rd': <gavo.rscdef.common.RDAttribute object>}¶
- name_ = 'nullCore'¶
- outputTableXML = '<outputTable/>'¶
- property rd¶
- setProperty(name, value)¶
- class gavo.svcs.standardcores.PhraseMaker(parent, **kwargs)[source]¶
Bases:
ProcApp
A procedure application for generating SQL expressions from input keys.
PhraseMaker code must yield SQL fragments that can occur in WHERE clauses, i.e., boolean expressions (thus, they must be generator bodies). The clauses yielded by a single condDesc are combined with the joiner set in the containing CondDesc (default=OR).
The following names are available to them:
inputKeys – the list of input keys for the parent CondDesc
inPars – a dictionary mapping inputKey names to the values provided by the user
- outPars – a dictionary that is later used as the parameter
dictionary to the query.
core – the core to which this phrase maker’s condDesc belongs
To get the standard SQL a single key would generate, say:
yield base.getSQLForField(inputKeys[0], inPars, outPars)
To insert some value into outPars, do not simply use some key into outParse, since, e.g., the condDesc might be used multiple times. Instead, use getSQLKey, maybe like this:
ik = inputKeys[0] yield "%s BETWEEN %%(%s)s AND %%(%s)s"%(ik.name, base.getSQLKey(ik.name, inPars[ik.name]-10, outPars), base.getSQLKey(ik.name, inPars[ik.name]+10, outPars))
getSQLKey will make sure unique names in outPars are chosen and enters the values there.
- 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>]¶
- completedCallbacks = []¶
- formalArgs = 'self, inputKeys, inPars, outPars, core'¶
- 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>}¶
- name_ = 'phraseMaker'¶
- requiredType = 'phraseMaker'¶
- class gavo.svcs.standardcores.TableBasedCore(parent, **kwargs)[source]¶
Bases:
Core
A core knowing a DB table it operates on and allowing the definition of condDescs.
- adaptForRenderer(renderer, queryMeta)[source]¶
returns a core tailored to renderer renderers.
This mainly means asking the condDescs to build themselves for a certain renderer. If no polymorphuous condDescs are there, self is returned.
- attrSeq = [<gavo.base.complexattrs.StructListAttribute object>, <gavo.base.parsecontext.IdAttribute object>, <gavo.base.complexattrs.StructAttribute object>, <gavo.rscdef.common.NamePathAttribute object>, <gavo.base.parsecontext.OriginalAttribute object>, <gavo.base.complexattrs.StructAttribute object>, <gavo.base.complexattrs.PropertyAttribute object>, <gavo.base.parsecontext.ReferenceAttribute object>, <gavo.rscdef.common.RDAttribute object>]¶
- clearProperty(name)¶
- completedCallbacks = []¶
- getFullId()¶
- getProperty(name, default=<Undefined>)¶
- getRelevantTables()[source]¶
returns a sequence of “published tables”.
This is for VOSI tables, and hence what’s a “published table” is a bit fuzzy. By default we return the output table if it looks non-trivial, or else nothing at all.
- hasProperty(name)¶
- managedAttrs = {'condDesc': <gavo.base.complexattrs.StructListAttribute object>, 'condDescs': <gavo.base.complexattrs.StructListAttribute object>, 'id': <gavo.base.parsecontext.IdAttribute object>, 'inputTable': <gavo.base.complexattrs.StructAttribute object>, 'namePath': <gavo.rscdef.common.NamePathAttribute object>, 'original': <gavo.base.parsecontext.OriginalAttribute object>, 'outputTable': <gavo.base.complexattrs.StructAttribute object>, 'properties': <gavo.base.complexattrs.PropertyAttribute object>, 'property': <gavo.base.complexattrs.PropertyAttribute object>, 'queriedTable': <gavo.base.parsecontext.ReferenceAttribute object>, 'rd': <gavo.rscdef.common.RDAttribute object>}¶
- property rd¶
- resolveName(context, id)¶
- setProperty(name, value)¶