def locateChild(self, ctx, segments): request = inevow.IRequest(ctx) uwsactions.lowercaseProtocolArgs(request.args) if not segments[-1]: # trailing slashes are forbidden here if len(segments ) == 1: # root resource; don't redirect, it would be a loop return self, () raise svcs.WebRedirect( self.service.getURL("tap") + "/" + "/".join(segments[:-1])) try: self.gatherUploadFiles(request) if (getTAPVersion() != utils.getfirst(request.args, "version", getTAPVersion())): return uwsactions.ErrorResource({ "msg": "Version mismatch; this service only supports" " TAP version %s." % getTAPVersion(), "type": "ValueError", "hint": "" }), () if segments: if segments[0] == 'sync': res = getSyncResource(ctx, self.service, segments[1:]) elif segments[0] == 'async': res = asyncrender.getAsyncResource(ctx, tap.WORKER_SYSTEM, "tap", self.service, segments[1:]) elif segments[0] == 'availability': res = vosi.VOSIAvailabilityRenderer(ctx, self.service) elif segments[0] == 'capabilities': res = vosi.VOSICapabilityRenderer(ctx, self.service) elif segments[0] == 'tables': res = vosi.VOSITablesetRenderer(ctx, self.service) elif segments[0] == 'examples': from gavo.web import examplesrender res = examplesrender.Examples(ctx, self.service) else: raise svcs.UnknownURI("Bad TAP path %s" % "/".join(segments)) return res, () except svcs.UnknownURI: raise except base.Error, ex: # see flagError in protocols.uws for the reason for the next if if not isinstance(ex, (base.ValidationError, uws.JobNotFound)): base.ui.notifyError("TAP error") return uwsactions.ErrorResource(ex), ()
def renderHTTP(self, ctx): try: return threads.deferToThread(self._doRender, ctx).addCallback( self._formatResult, ctx).addErrback(self._formatError) except base.Error, ex: base.ui.notifyExceptionMutation(None) return uwsactions.ErrorResource(ex)
def _deliverError(self, failure, request): # let auth requests fall through if isinstance(failure.value, svcs.Authenticate): return failure if not isinstance(failure.value, uws.JobNotFound): base.ui.notifyFailure(failure) request.setHeader("content-type", "text/xml") return uwsactions.ErrorResource(failure.value)
def getSyncResource(ctx, service, segments): if segments: raise svcs.UnknownURI("No resources below sync") request = common.getfirst(ctx, "request", base.Undefined) if request == "doQuery": return TAPQueryResource(service, ctx) elif request == "getCapabilities": return vosi.VOSICapabilityRenderer(ctx, service) return uwsactions.ErrorResource({ "type": "ParameterError", "msg": "Invalid REQUEST: '%s'" % request, "hint": "Only doQuery and getCapabilities supported here" })
def _formatError(self, failure): base.ui.notifyFailure(failure) return uwsactions.ErrorResource(failure.value)