gavo.svcs.inputdef module

Description and handling of inputs to services.

This module in particular describes the InputKey, the primary means of describing input widgets and their processing.

They are collected in contextGrammars, entities creating inputArgs items.

class gavo.svcs.inputdef.ContextGrammar(parent, **kwargs)[source]

Bases: Grammar

A grammar for web inputs.

The source tokens for context grammars are dictionaries; these are either typed dictionaries from gavo.formal, where the values usually are atomic, or, preferably, the dictionaries of lists from request.strargs.

ContextGrammars never yield rows, so they’re probably fairly useless in normal circumstances.

In normal usage, they just yield a single parameter row, corresponding to the source dictionary possibly completed with defaults, where non-requried input keys get None defaults where not given. Missing required parameters yield errors.

This parameter row honors the multiplicity specification, i.e., single or forced-single are just values, multiple are lists. The content are parsed values (using the InputKeys’ parsers).

Since most VO protocols require case-insensitive matching of parameter names, matching of input key names and the keys of the input dictionary is attempted first literally, then disregarding case.

Since ContextGrammars can be parents of inputKeys and thus are a bit table-like, they can also carry metadata.

attrSeq = [<gavo.base.attrdef.UnicodeAttribute object>, <gavo.base.parsecontext.IdAttribute object>, <gavo.base.complexattrs.StructAttribute object>, <gavo.base.complexattrs.StructListAttribute object>, <gavo.base.parsecontext.ReferenceAttribute object>, <gavo.base.parsecontext.OriginalAttribute object>, <gavo.base.complexattrs.PropertyAttribute object>, <gavo.rscdef.common.RDAttribute object>, <gavo.base.complexattrs.StructListAttribute object>, <gavo.base.complexattrs.StructAttribute object>]
clearProperty(name)
completedCallbacks = []
getFullId()
getProperty(name, default=<Undefined>)
hasProperty(name)
iterInputKeys()[source]
managedAttrs = {'enc': <gavo.base.attrdef.UnicodeAttribute object>, 'id': <gavo.base.parsecontext.IdAttribute object>, 'ignoreOn': <gavo.base.complexattrs.StructAttribute object>, 'inputKey': <gavo.base.complexattrs.StructListAttribute object>, 'inputKeys': <gavo.base.complexattrs.StructListAttribute object>, 'inputTD': <gavo.base.parsecontext.ReferenceAttribute object>, 'original': <gavo.base.parsecontext.OriginalAttribute object>, 'properties': <gavo.base.complexattrs.PropertyAttribute object>, 'property': <gavo.base.complexattrs.PropertyAttribute object>, 'rd': <gavo.rscdef.common.RDAttribute object>, 'rowfilter': <gavo.base.complexattrs.StructListAttribute object>, 'rowfilters': <gavo.base.complexattrs.StructListAttribute object>, 'sourceFields': <gavo.base.complexattrs.StructAttribute object>}
name_ = 'contextGrammar'
onElementComplete()[source]
parseStrargs(strargs, ensureRequired=True)[source]

returns parsed parameters from a request.strargs dict.

This is a convenience method appropriate here because, really, ContextGrammars never yield rows, and hence the calling convention is a bit counter-intuitive.

ensureRequired=False asks the context grammar to not complain if required values are missing. That is important in UWS operation, where parameters may be set incrementally.

property rd
rejectExtras = False
rowIterator

alias of ContextRowIterator

setProperty(name, value)
class gavo.svcs.inputdef.ContextRowIterator(grammar, sourceToken, **kwargs)[source]

Bases: RowIterator

is a row iterator over “contexts”, i.e. single dictionary-like objects.

The source token expected here can be a request.strargs style dictionary with lists of strings as arguments, or a parsed dictionary from gavo.formal. Non-list literals in the latter are packed into a list to ensure consistent behaviour.

getLocator()[source]
getParameters()[source]
class gavo.svcs.inputdef.CoreArgs(inputTD, args, rawArgs)[source]

Bases: MetaMixin

A container for core arguments.

There’s inputTD, which reference the renderer-adapted input table, and args, the ContextGrammar processed input. For kicks, we also have rawArgs, which is the contextGrammar’s input (if you find you’re using it, tell us; that’s pointing to a problem on our side).

getParam(name) -> value and getParamDict() -> dict methods are present for backward compatibility.

classmethod fromRawArgs(inputTD, rawArgs, contextGrammar=None)[source]

returns a CoreArgs instance built from an inputDD and ContextGrammar-parseable rawArgs.

contextGrammar can be overridden, e.g., to cache or to add extra, non-core keys.

getParam(name)[source]
getParamDict()[source]
update(other)[source]

adds (and overwrites) the parameters from another CoreArgs instance to this.

This is used in UWS processing, where generic and service-specific parameters are parsed in two steps.

Right now, the inputTD is taken from other; we may find that we need to merge the two inputTDs later, so there are no guarantees that the first inputKeys disappear.

We also assume that the rawArgs are always the same.

class gavo.svcs.inputdef.InputKey(parent, **kwargs)[source]

Bases: ParamBase

A description of a piece of input.

Think of inputKeys as abstractions for input fields in forms, though they are used for services not actually exposing HTML forms as well.

Some of the DDL-type attributes (e.g., references) only make sense here if columns are being defined from the InputKey.

Properties evaluated:

  • defaultForForm – a value entered into form fields by default (be stingy with those; while it’s nice to not have to set things presumably right for almost everyone, having to delete stuff you don’t want over and over is really annoying).

  • adaptToRenderer – a true boolean literal here causes the param to be adapted for the renderer (e.g., float could become vexpr-float). You’ll usually not want this, because the expressions are generally evaluated by the database, and the condDescs do the adaptation themselves. This is mainly for rare situations like file uploads in custom cores.

  • notForRenderer – a renderer name for which this inputKey is suppressed

  • onlyForRenderer – a renderer name for which this inputKey will be preserved; it will be dropped for all others.

attrSeq = [<gavo.base.meta.MetaAttribute object>, <gavo.rscdef.column.ParamNameAttribute object>, <gavo.rscdef.column.TypeNameAttribute object>, <gavo.base.attrdef.UnicodeAttribute object>, <gavo.base.attrdef.UnicodeAttribute object>, <gavo.base.attrdef.NWUnicodeAttribute object>, <gavo.rscdef.column.TableManagedAttribute object>, <gavo.base.parsecontext.OriginalAttribute object>, <gavo.base.attrdef.UnicodeAttribute object>, <gavo.base.attrdef.BooleanAttribute object>, <gavo.base.complexattrs.PropertyAttribute object>, <gavo.base.attrdef.UnicodeAttribute object>, <gavo.base.attrdef.UnicodeAttribute object>, <gavo.base.complexattrs.StructAttribute object>, <gavo.rscdef.column.DisplayHintAttribute object>, <gavo.base.attrdef.UnicodeAttribute object>, <gavo.base.structure.DataContent object>, <gavo.base.attrdef.UnicodeAttribute object>, <gavo.base.attrdef.UnicodeAttribute object>, <gavo.rscdef.column.TableManagedAttribute object>, <gavo.base.attrdef.UnicodeAttribute object>, <gavo.base.attrdef.BooleanAttribute object>, <gavo.base.parsecontext.IdAttribute object>, <gavo.rscdef.column.DMRolesAttribute object>, <gavo.base.attrdef.UnicodeAttribute object>, <gavo.base.attrdef.UnicodeAttribute object>, <gavo.base.attrdef.IntAttribute object>, <gavo.base.attrdef.IntAttribute object>]
clearProperty(name)
completeElement(ctx)[source]
completedCallbacks = []
computeCoreArgValue(inputList, ensureRequired=True)[source]

parses some input for this input key.

This takes into account multiplicities, type conversions, and all the remaining horrors.

It will return a list or a single value, depending on multiplity.

classmethod fromColumn(column, **kwargs)[source]

returns an InputKey for query input to column.

getProperty(name, default=<Undefined>)
hasProperty(name)
managedAttrs = {'content_': <gavo.base.structure.DataContent object>, 'description': <gavo.base.attrdef.NWUnicodeAttribute object>, 'displayHint': <gavo.rscdef.column.DisplayHintAttribute object>, 'dmRoles': <gavo.rscdef.column.DMRolesAttribute object>, 'fixup': <gavo.base.attrdef.UnicodeAttribute object>, 'id': <gavo.base.parsecontext.IdAttribute object>, 'inputUnit': <gavo.base.attrdef.UnicodeAttribute object>, 'meta': <gavo.base.meta.MetaAttribute object>, 'meta_': <gavo.base.meta.MetaAttribute object>, 'multiplicity': <gavo.base.attrdef.UnicodeAttribute object>, 'name': <gavo.rscdef.column.ParamNameAttribute object>, 'note': <gavo.base.attrdef.UnicodeAttribute object>, 'original': <gavo.base.parsecontext.OriginalAttribute object>, 'preparse': <gavo.base.attrdef.UnicodeAttribute object>, 'properties': <gavo.base.complexattrs.PropertyAttribute object>, 'property': <gavo.base.complexattrs.PropertyAttribute object>, 'required': <gavo.base.attrdef.BooleanAttribute object>, 'showItems': <gavo.base.attrdef.IntAttribute object>, 'stc': <gavo.rscdef.column.TableManagedAttribute object>, 'stcUtype': <gavo.rscdef.column.TableManagedAttribute object>, 'std': <gavo.base.attrdef.BooleanAttribute object>, 'tablehead': <gavo.base.attrdef.UnicodeAttribute object>, 'type': <gavo.rscdef.column.TypeNameAttribute object>, 'ucd': <gavo.base.attrdef.UnicodeAttribute object>, 'unit': <gavo.base.attrdef.UnicodeAttribute object>, 'utype': <gavo.base.attrdef.UnicodeAttribute object>, 'values': <gavo.base.complexattrs.StructAttribute object>, 'verbLevel': <gavo.base.attrdef.IntAttribute object>, 'widgetFactory': <gavo.base.attrdef.UnicodeAttribute object>, 'xtype': <gavo.base.attrdef.UnicodeAttribute object>}
metaModel = None
name_ = 'inputKey'
onElementComplete()[source]
onParentComplete()[source]
setProperty(name, value)
validateValue(literal)[source]

raises a ValidationError if literal cannot be deserialised into an acceptable value for self.

class gavo.svcs.inputdef.InputTD(parent, **kwargs)[source]

Bases: Structure, StandardMacroMixin

an input for a core.

These aren’t actually proper tables but actually just collection of the param-like inputKeys. They serve as input declarations for cores and services (where services derive their inputTDs from the cores’ ones by adapting them to the current renderer. Their main use is for the derivation of contextGrammars.

They can carry metadata, though, which is sometimes convenient when transporting information from the parameter parsers to the core.

For the typical dbCores (and friends), these are essentially never explicitly defined but rather derived from condDescs.

Do not read input values by using table.getParam. This will only give you one value when a parameter has been given multiple times. Instead, use the output of the contextGrammar (inputParams in condDescs). Only there you will have the correct multiplicities.

adaptForRenderer(renderer)[source]

returns an inputTD tailored for renderer.

This is discussed in svcs.core’s module docstring.

attrSeq = [<gavo.base.attrdef.BooleanAttribute object>, <gavo.base.complexattrs.StructListAttribute object>, <gavo.base.parsecontext.IdAttribute object>, <gavo.rscdef.common.ColumnListAttribute object>, <gavo.rscdef.common.RDAttribute object>]
completedCallbacks = []
getFullId()
managedAttrs = {'exclusive': <gavo.base.attrdef.BooleanAttribute object>, 'group': <gavo.base.complexattrs.StructListAttribute object>, 'groups': <gavo.base.complexattrs.StructListAttribute object>, 'id': <gavo.base.parsecontext.IdAttribute object>, 'inputKey': <gavo.rscdef.common.ColumnListAttribute object>, 'inputKeys': <gavo.rscdef.common.ColumnListAttribute object>, 'rd': <gavo.rscdef.common.RDAttribute object>}
name_ = 'inputTable'
property rd
resolveName(ctx, name)[source]

returns a column name from a queried table of the embedding core, if available.

This is a convenicence hack that lets people reference columns from a TableBasedCore by their simple, non-qualified names.

gavo.svcs.inputdef.filterInputKeys(keys, rendName, adaptor=None)[source]

filters inputKeys in key, only returning those compatible with rendName.

adaptor is is a function taking and returning an inputKey that is used for input keys with an adaptToRenderer property.

gavo.svcs.inputdef.getRendererAdaptor(renderer)[source]

returns a function that returns input keys adapted for renderer.

The function returns None if no adapter is necessary. This only takes place for inputKeys within a buildFrom condDesc.