gavo.svcs.common module

Common functions and classes for services and cores.

exception gavo.svcs.common.Authenticate(realm='Gavo', hint=None)[source]

Bases: Error

raised to initiate an authentication request.

Authenticates are optionally constructed with the realm the user shall authenticate in. If you leave the realm out, the DC-wide default will be used.

exception gavo.svcs.common.BadMethod(msg, rd=None, hint=None, htmlMessage=None)[source]

Bases: Error

raised to generate an HTTP 405 response.

exception gavo.svcs.common.Error(msg, rd=None, hint=None, htmlMessage=None)[source]

Bases: ExecutiveAction

exception gavo.svcs.common.ForbiddenURI(msg, rd=None, hint=None, htmlMessage=None)[source]

Bases: Error

raised to generate an HTTP 403 response.

exception gavo.svcs.common.Found(dest, hint=None)[source]

Bases: RedirectBase

raised to redirect a user agent to a different resource (HTTP 302).

Found instances are constructed with the destination URL that can be relative (to webRoot) or absolute (starting with http).

They are essentially like WebRedirect, except they put out a 302 instead of a 301.

class gavo.svcs.common.QueryMeta(initArgs=None, defaultLimit=None)[source]

Bases: dict

A class keeping information on the query environment.

It is constructed with a plain dictionary (there are alternative constructors for t.w requests are below) mapping certain keys (you’ll currently have to figure out which from the source) to values, mostly strings, except for the keys listed in listKeys, which should be sequences of strings.

If you pass an empty dict, some sane defaults will be used. You can get that “empty” query meta as common.emptyQueryMeta, but make sure you don’t mutate it.

QueryMetas constructed from request will have the user and password items filled out.

If you’re using formal, you should set the formal_data item to the dictionary created by formal. This will let people use the parsed parameters in templates.

Note: You cannot trust qm[“user”] – it is not validated against any credentials.

asSQL()[source]

returns the dbLimit and dbSortKey values as an SQL fragment.

classmethod fromRequest(request, **kwargs)[source]

constructs a QueryMeta from a gavo.web.common.Request.

In addition to getting information from the arguments, this also sets user and password.

classmethod fromRequestArgs(inArgs, **kwargs)[source]

constructs a QueryMeta from a gavo.web.common.Request.strargs

listKeys = {'_ADDITEM', '_DBOPTIONS_ORDER', '_SET'}
overrideDbOptions(sortKeys=None, limit=None, sortFallback=None, direction=None)[source]
exception gavo.svcs.common.RedirectBase(dest, hint=None)[source]

Bases: Error

exception gavo.svcs.common.RequestEntityTooLarge(*args, **kwargs)[source]

Bases: Error

raised to generate an HTTP 413 response.

exception gavo.svcs.common.SeeOther(dest, hint=None)[source]

Bases: RedirectBase

raised to redirect a user agent to a different resource (HTTP 303).

SeeOthers are constructed with the destination URL that can be relative (to webRoot) or absolute (starting with http).

They are essentially like WebRedirect, except they put out a 303 instead of a 301.

exception gavo.svcs.common.UnknownURI(msg, rd=None, hint=None, htmlMessage=None)[source]

Bases: Error, NotFoundError

raised to generate an HTTP 404 response.

exception gavo.svcs.common.WebRedirect(dest, hint=None)[source]

Bases: RedirectBase

raised to redirect a user agent to a different resource (HTTP 301).

WebRedirectes are constructed with the destination URL that can be relative (to webRoot) or absolute (starting with http).

gavo.svcs.common.getTemplatePath(key)[source]

see loadSystemTemplate.

gavo.svcs.common.loadSystemTemplate(key)[source]

returns a nevow template for system pages from key.

path is interpreted as relative to gavo_root/web/templates (first) and package internal (last). If no template is found, None is returned (this harmonizes with the fallback in CustomTemplateMixin).

Note that nevowc.XMLFile at this point ignores the doctype of the template. For non-XHTML doctypes, set a gavo_useDoctype attribute on the renderer.

gavo.svcs.common.parseServicePath(serviceParts)[source]

returns a tuple of resourceDescriptor, serviceName.

A service id consists of an inputsDir-relative path to a resource descriptor, a slash, and the name of a service within this descriptor.

This function returns a tuple of inputsDir-relative path and service name. It raises a gavo.Error if sid has an invalid format. The existence of the resource or the service are not checked.