gavo.protocols.dali module

Common code supporting functionality described in DALI.

class gavo.protocols.dali.DALIErrorResource(errInfo)[source]

Bases: twisted.web.resource.Resource

A DALI error (i.e., an INFO in a VOTable.

This is constructed with an exception or a UWS errInfo (see getDALIError).

Use this when you want to return a DALI error from within a getChild function. Otherwise, just use serveDALIError.

isLeaf = True

Render a given resource. See L{IResource}’s render method.

I delegate to methods of self with the form ‘render_METHOD’ where METHOD is the HTTP that was used to make the request. Examples: render_GET, render_HEAD, render_POST, and so on. Generally you should implement those methods instead of overriding this one.

render_METHOD methods are expected to return a byte string which will be the rendered page, unless the return value is C{server.NOT_DONE_YET}, in which case it is this class’s responsibility to write the results using C{request.write(data)} and then call C{request.finish()}.

Old code that overrides render() directly is likewise expected to return a byte string or NOT_DONE_YET.

@see: L{IResource.render}

class gavo.protocols.dali.URLUpload(uploadURL, uploadName)[source]

Bases: object

a somewhat FieldStorage-compatible facade to an upload coming from a URL.

The filename for now is the complete upload URL, but that’s likely to change.

property value
gavo.protocols.dali.getDALIError(errInfo, queryStatus='ERROR')[source]

returns a DALI-compliant error VOTable from an error info.

errInfo can either be an exception, a UWS error info (a dict with keys msg, type, and hint), or a pre-formatted string.


returns an input key for file items in “PQL”.

This is actually specified by DALI. In that scheme, the parameter is always called UPLOAD (there can thus only be one such parameter, but it can be present multiple times in calls if necessary, except we’ve not figured out how to do the description right in that case).

It contains a comma-separated (key,source) pair, where source is a URL; there’s a special scheme param: for referring to inline uploads by their name.

This is used exclusively for metadata generation, and there’s special code to handle it there. There’s also special code in mangleUploads (called by, e.g., the ApiRenderer) to magcially make UPLOAD into the file parameters we use within DaCHS. Sigh.


iterates over DALI uploads in request.

This yields pairs of (file name, file object), where file name is the file name requested (sanitized to have no slashes and non-ASCII). The UPLOAD and inline-file keys are removed from request’s args member. The file object is a cgi-style thing with file, filename, etc. attributes.


manipulates request such that DALI UPLOADs appear in strargs as pairs of name and file/URLUpload

These are as in normal CGI: uploads are under “their names” (with DALI uploads, the resource names), with values being pairs of some name and a FieldStorage-compatible thing having name, filename, value, file, type, type_options, and headers.

This will also overwrite upload with a sequence of (name, file) for all uploads for the benefit of uws.

There’s extra code for this in TAP because regrettably TAP works a bit differently from this.


returns resourceName, uploadSource from a DALI upload string.

gavo.protocols.dali.serveDALIError(request, errInfo, httpStatus=200, queryStatus='ERROR')[source]

serves a DALI-compliant error message from errInfo.

See getDALIError for what errInfo can be.

This closes the request and returns NOT_DONE_YET, so you can write return serverDALIError in normal render functions

DALI isn’t quite clear on what httpCode ought to be, and protocols sometimes actually require it to be 200 even of errors (sigh). To return non-200, pass an httpCode