gavo.svcs.service module¶
Services, i.e. combinations of a core and at least one renderer.
See the __init__.py docstring for a bit more on the general architecture.
- class gavo.svcs.service.CoreAttribute[source]¶
Bases:
ReferenceAttribute
- class gavo.svcs.service.CustomDF(parent, **kwargs)[source]¶
Bases:
CustomPageFunction
A custom data function for a service.
Custom data functions can be used to expose certain aspects of a service to Nevow templates. Thus, their definition usually only makes sense with custom templates, though you could, in principle, override built-in render functions.
In the data functions, you have the names ctx for a context and data for the “current data” (i.e., what’s last been set using n:data). In ctx, only use ctx.tag (the tag on which the n:render attribute sits) and, if necessary ctx.request (the t.w request object).
Also, the active renderer is visible as self; the one thing you might want to see from there is self.queryMeta, which contains, for instance, the input parameters.
You can access the embedding service as service, the embedding RD as service.rd.
You can return arbitrary python objects – whatever the render functions can deal with. You could, e.g., write:
<customDF name="now"> return datetime.datetime.utcnow() </customDF>
You can use the request to fetch request parameters. Within DaCHS, in addition to the clumsy request.args (mapping bytes to bytes), there is also request.strargs (mapping strings to strings). So, access a query parameter
order
like this:sortOrder = ctx.request.strargs.get("order", ["authors"])
- attrSeq = [<gavo.base.structure.DataContent object>, <gavo.base.parsecontext.IdAttribute object>, <gavo.base.attrdef.UnicodeAttribute object>]¶
- completedCallbacks = []¶
- managedAttrs = {'content_': <gavo.base.structure.DataContent object>, 'id': <gavo.base.parsecontext.IdAttribute object>, 'name': <gavo.base.attrdef.UnicodeAttribute object>}¶
- name_ = 'customDF'¶
- class gavo.svcs.service.CustomPageFunction(parent, **kwargs)[source]¶
Bases:
Structure
,RestrictionMixin
An abstract base for t.w.resource.Resource-related functions on services.
- attrSeq = [<gavo.base.structure.DataContent object>, <gavo.base.parsecontext.IdAttribute object>, <gavo.base.attrdef.UnicodeAttribute object>]¶
- completedCallbacks = []¶
- managedAttrs = {'content_': <gavo.base.structure.DataContent object>, 'id': <gavo.base.parsecontext.IdAttribute object>, 'name': <gavo.base.attrdef.UnicodeAttribute object>}¶
- class gavo.svcs.service.CustomRF(parent, **kwargs)[source]¶
Bases:
CustomPageFunction
A custom render function for a service.
Custom render functions can be used to expose certain aspects of a service to Nevow templates. Thus, their definition usually only makes sense with custom templates, though you could, in principle, override built-in render functions.
In the render functions, you have the names ctx for a context and data for the “current data” (i.e., what’s last been set using n:data). In ctx, only use ctx.tag (the tag on which the n:render attribute sits) and, if necessary ctx.request (the t.w request object).
Also, the active renderer is visible as self; the one thing you might want to see from there is self.queryMeta, which contains, for instance, the input parameters (but be careful: the inputTable will be None when input errors are rendered, so better to code using it like this:
if self.queryMeta["inputTable"] and self.queryMeta["inputTable"]...:
You can return anything that can be in a stan DOM. Usually, this will be a string. To return HTML, use the stan DOM available under the T namespace.
As an example, the following code returns the current data as a link:
return ctx.tag[T.a(href=data)[data]]
You can access the embedding service as service, the embedding RD as service.rd.
- attrSeq = [<gavo.base.structure.DataContent object>, <gavo.base.parsecontext.IdAttribute object>, <gavo.base.attrdef.UnicodeAttribute object>]¶
- completedCallbacks = []¶
- managedAttrs = {'content_': <gavo.base.structure.DataContent object>, 'id': <gavo.base.parsecontext.IdAttribute object>, 'name': <gavo.base.attrdef.UnicodeAttribute object>}¶
- name_ = 'customRF'¶
- class gavo.svcs.service.PreparsedInput[source]¶
Bases:
dict
a sentinel class signalling to the service that its input already is parsed.
This is for for stuff coming from nevow formal rather than request.strargs, and to be fed into service.run.
Construct with a dictionary.
- class gavo.svcs.service.Publication(parent, **kwargs)[source]¶
Bases:
Structure
,ComputedMetaMixin
A specification of how a service should be published.
This contains most of the metadata for what is an interface in registry speak.
- attrSeq = [<gavo.base.attrdef.BooleanAttribute object>, <gavo.base.parsecontext.IdAttribute object>, <gavo.base.meta.MetaAttribute object>, <gavo.rscdef.common.RDAttribute object>, <gavo.base.attrdef.UnicodeAttribute object>, <gavo.base.parsecontext.ReferenceAttribute object>, <gavo.base.attrdef.StringSetAttribute object>]¶
- completedCallbacks = []¶
- getFullId()¶
- managedAttrs = {'auxiliary': <gavo.base.attrdef.BooleanAttribute object>, 'id': <gavo.base.parsecontext.IdAttribute object>, 'meta': <gavo.base.meta.MetaAttribute object>, 'meta_': <gavo.base.meta.MetaAttribute object>, 'rd': <gavo.rscdef.common.RDAttribute object>, 'render': <gavo.base.attrdef.UnicodeAttribute object>, 'service': <gavo.base.parsecontext.ReferenceAttribute object>, 'sets': <gavo.base.attrdef.StringSetAttribute object>}¶
- name_ = 'publish'¶
- property rd¶
- class gavo.svcs.service.Service(parent, **kwargs)[source]¶
Bases:
Structure
,ComputedMetaMixin
,StandardMacroMixin
,IVOMetaMixin
A service definition.
A service is a combination of a core and one or more renderers. They can be published, and they carry the metadata published into the VO.
You can set the defaultSort property on the service to a name of an output column to preselect a sort order. Note again that this will slow down responses for all but the smallest tables unless there is an index on the corresponding column.
Properties evaluated:
votableRespectsOutputTable – usually, VOTable output puts in all columns from the underlying database table with low enough verbLevel (essentially). When this property is “True” (case-sensitive),
that’s not done and only the service’s output table is evaluated.
fixedFormat – if this is set to “True”, the form renderer will not produce an output format selector (and we shouldn’t produce DALI RESPONSEFORMAT metadata).
- adaptCoreRes(coreRes, queryMeta)[source]¶
adapts a core result to the service’s output table if appropriate.
Frankly, this was an early mis-design that complicates matters unnecessarily, but I can’t really drop it as long as some interesting things are based on service’s outputTables.
The adaptation works like this:
(0) if coreRes isn’t a table, or that table has a noPostprocess attribute, return coreRes and let the renderer worry about it.
(1) if names and units of newColumns the same as coreRes.columns, accept coreRes as the new table
(2) if names of newColumns are a subset of coreRes.columns match but one or more units don’t, set up a conversion routine and create new rows, combining them with newColumns to the result.
else raise an error
(4) eventually, wrap everything up in a rsc.Data instance for compatibility with cores actually returning data items.
- attrSeq = [<gavo.base.attrdef.StringSetAttribute object>, <gavo.svcs.service.CoreAttribute object>, <gavo.base.complexattrs.StructListAttribute object>, <gavo.rscdef.common.ResdirRelativeAttribute object>, <gavo.base.complexattrs.StructListAttribute object>, <gavo.base.attrdef.UnicodeAttribute object>, <gavo.base.parsecontext.IdAttribute object>, <gavo.base.attrdef.UnicodeAttribute object>, <gavo.base.meta.MetaAttribute object>, <gavo.base.parsecontext.OriginalAttribute object>, <gavo.base.complexattrs.StructAttribute object>, <gavo.base.complexattrs.PropertyAttribute object>, <gavo.base.complexattrs.StructListAttribute object>, <gavo.rscdef.common.RDAttribute object>, <gavo.base.complexattrs.UniquedStructListAttribute object>, <gavo.base.complexattrs.DictAttribute object>]¶
- clearProperty(name)¶
- completedCallbacks = []¶
- property customPage¶
- declareServes(data)[source]¶
adds meta to self and data indicating that data is served by this service.
This is used by table/@adql and the publish element on data.
- getAllOutputFields()[source]¶
Returns a sequence of all available output fields.
This is what the core gives, and this is what will be declared to the registry. Depending on the output format, the verbosity level and perhaps other user settings, the actual columns produced will be different.
- getBrowserURL(fq=True)[source]¶
returns a published URL that’s suitable for a web browser or None if no such URL can be guessed.
If you pass fq=False, you will get a path rather than a URL.
- getContextGrammarFor(renderer, queryMeta, core=None)[source]¶
returns an ContextGrammar appropriate for this renderer.
Pass in the core if you already have it as an optimisation (in particular for datalink, where cores aren’t automatically cached); if you don’t the core will be computed from the renderer.
In either case, the context grammar simply is built from the core’s inputTable.
- getCoreFor(renderer, queryMeta)[source]¶
returns a core tailored for renderer.
See svcs.core’s module docstring.
The argument can be a renderer or a renderer name.
- getCurOutputFields(queryMeta=None, raiseOnUnknown=True)[source]¶
returns a list of desired output fields for query meta.
This is for both the core and the formatter to figure out the structure of the tables passed.
- getFullId()¶
- getHTMLOutputFields(queryMeta, ignoreAdditionals=False, raiseOnUnknown=True)[source]¶
returns a list of OutputFields suitable for an HTML response described by queryMeta.
This is the service’s output table if given, else the core’s output table at verbLevel 2. Additional fields can be set by the user.
raiseOnUnknown is used by customwidgets to avoid exceptions because of bad additional fields during form construction (when they aren’t properly caught).
- getInputKeysFor(renderer, queryMeta={'accept': {}, 'additionalFields': [], 'columnSet': None, 'dbLimit': 100, 'dbSortKeys': [], 'direction': 'ASC', 'formal_data': {}, 'inputTable': None, 'password': None, 'tdEnc': False, 'timeout': 15, 'user': None, 'verbosity': 20})[source]¶
returns a sequence of input keys, adapted for renderer.
The renderer argument may either be a renderer name, a renderer class or a renderer instance.
This is the main interface for external entities to discover. service metadata.
- getProperty(name, default=<Undefined>)¶
- getPublicationsForSet(names, includeDatalink=True)[source]¶
returns publications for a set of set names (the names argument).
In the special case names=None, all allowed renderers are treated as published.
- getTableSet()[source]¶
returns a list of table definitions that have something to do with this service.
This is for VOSI-type requests.
Basically, we’re leaving the decision to the core, except when we have an output Table of our own.
- getTemplate(key, reload=False)[source]¶
returns the nevow template for the function key on this service.
Pass reload to force a reload of templates already parsed.
- getURL(rendName, absolute=True, canonical=False, **kwargs)[source]¶
returns the full canonical access URL of this service together with renderer.
rendName is the name of the intended renderer in the registry of renderers.
With absolute, a fully qualified URL is being returned.
Further keyword arguments are translated into URL parameters in the query part.
- getUWS()[source]¶
returns the UWS worker system for this service.
This is a service for the DALIAsyncRenderer.
- hasProperty(name)¶
- htmlLikeFormats = ['HTML', 'tar']¶
- isBrowseableWith(rendName)[source]¶
returns true if rendering this service through rendName results in something pretty in a web browser.
- property isVOPublished¶
is true if there is any ivo_managed publication on this service.
If renderer is non-None, only publications with this renderer name count.
- macro_tablesForTAP()[source]¶
returns a list of table names available for TAP querying.
This, really, is an implementation detail for the TAP service and might go away anytime.
- managedAttrs = {'adqlCore': <gavo.svcs.service.CoreAttribute object>, 'allowed': <gavo.base.attrdef.StringSetAttribute object>, 'core': <gavo.svcs.service.CoreAttribute object>, 'customCore': <gavo.svcs.service.CoreAttribute object>, 'customDF': <gavo.base.complexattrs.StructListAttribute object>, 'customDFs': <gavo.base.complexattrs.StructListAttribute object>, 'customPage': <gavo.rscdef.common.ResdirRelativeAttribute object>, 'customRF': <gavo.base.complexattrs.StructListAttribute object>, 'customRFs': <gavo.base.complexattrs.StructListAttribute object>, 'datalinkCore': <gavo.svcs.service.CoreAttribute object>, 'dbCore': <gavo.svcs.service.CoreAttribute object>, 'debugCore': <gavo.svcs.service.CoreAttribute object>, 'defaultRenderer': <gavo.base.attrdef.UnicodeAttribute object>, 'fancyQueryCore': <gavo.svcs.service.CoreAttribute object>, 'fixedQueryCore': <gavo.svcs.service.CoreAttribute object>, 'id': <gavo.base.parsecontext.IdAttribute object>, 'inputKey': <gavo.base.complexattrs.UniquedStructListAttribute object>, 'limitTo': <gavo.base.attrdef.UnicodeAttribute object>, 'meta': <gavo.base.meta.MetaAttribute object>, 'meta_': <gavo.base.meta.MetaAttribute object>, 'nullCore': <gavo.svcs.service.CoreAttribute object>, 'original': <gavo.base.parsecontext.OriginalAttribute object>, 'outputTable': <gavo.base.complexattrs.StructAttribute object>, 'productCore': <gavo.svcs.service.CoreAttribute object>, 'properties': <gavo.base.complexattrs.PropertyAttribute object>, 'property': <gavo.base.complexattrs.PropertyAttribute object>, 'publications': <gavo.base.complexattrs.StructListAttribute object>, 'publish': <gavo.base.complexattrs.StructListAttribute object>, 'pythonCore': <gavo.svcs.service.CoreAttribute object>, 'rd': <gavo.rscdef.common.RDAttribute object>, 'registryCore': <gavo.svcs.service.CoreAttribute object>, 'scsCore': <gavo.svcs.service.CoreAttribute object>, 'serviceKeys': <gavo.base.complexattrs.UniquedStructListAttribute object>, 'siapCutoutCore': <gavo.svcs.service.CoreAttribute object>, 'ssapCore': <gavo.svcs.service.CoreAttribute object>, 'tapCore': <gavo.svcs.service.CoreAttribute object>, 'template': <gavo.base.complexattrs.DictAttribute object>, 'templates': <gavo.base.complexattrs.DictAttribute object>, 'uploadCore': <gavo.svcs.service.CoreAttribute object>}¶
- metaModel = 'title(1), creationDate(1), description(1),subject, referenceURL(1), shortName(!)'¶
- name_ = 'service'¶
- property rd¶
- run(renderer, args, queryMeta)[source]¶
runs the service, returning a service result.
This is the main entry point for protocol renderers; args is a dict of lists as provided by request.strargs.
- setProperty(name, value)¶