def _getJob(self, jobId, conn, writable=False): """returns the named job as uws.UWS._getJob. However, in a user UWS, there can be jobs from multiple services. It would be nonsense to load another UWS's job's parameters into our job class. To prevent this, we redirect if we find the new job's class isn't ours. On the web interface, that should do the trick. Everywhere else, this may not be entirely clear but still prevent major confusion. This is repeating code from uws.UWS._getJob; some refactoring at some point would be nice. """ statementId = 'getById' if writable: statementId = 'getByIdEx' res = self.runCanned(statementId, {"jobId": jobId}, conn) if len(res)!=1: raise uws.JobNotFound(jobId) if res[0]["jobClass"]!=self.service.getFullId(): raise svcs.WebRedirect( base.resolveCrossId(res[0]["jobClass"]).getUWS().getURLForId(jobId)) return self.jobClass(res[0], self, writable)
def renderHTTP(self, ctx): """The resource itself is the indexFile or the directory listing. """ # make sure there always is a slash at the end of any URL # that points to any sort of index file (TODO: parse the URL?) request = inevow.IRequest(ctx) basePath = request.uri.split("?")[0] if basePath.endswith("static/"): if self.indexFile: return ifpages.StaticFile(self.indexFile, self.rd) else: return static.File(self.staticPath).directoryListing() elif basePath.endswith("static"): raise svcs.WebRedirect(request.uri + "/") else: raise svcs.WebRedirect(request.uri + "/static/")
def renderHTTP(self, ctx): # look for a matching publication in the parent service... for pub in self.service.publications: if pub.render == self.name: break else: # no publication, 404 raise svcs.UnknownURI( "No publication for an external service here.") raise svcs.WebRedirect( base.getMetaText(pub, "accessURL", macroPackage=self.service))
def locateChild(self, ctx, segments): request = inevow.IRequest(ctx) if request.uri.endswith("?wsdl"): # XXX TODO: use parsed headers here return self, () if request.method != 'POST': # SOAP only makes sense when data is posted; with no data, # twisted generates ugly tracebacks, and we may as well do # something sensible, like... redirect to the service's info # page raise svcs.WebRedirect(self.service.getURL("info")) return SOAPProcessor(ctx, self.service, self.runServiceFromArgs), ()
def locateChild(self, ctx, segments): # By default, ServiceBasedPages have no directory-like resources. # So, if some overzealous entity added a slash, just redirect. # Do not upcall to this if you override locateChild. if segments == ("", ): raise svcs.WebRedirect(url.URL.fromContext(ctx)) else: res = ResourceBasedPage.locateChild(self, ctx, segments) if res[0] is None: raise svcs.UnknownURI("%s has no child resources" % repr(self.name)) return res
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 locateChild(self, ctx, segments): from gavo.protocols import uwsactions from gavo.web import asyncrender # no trailing slashes here, ever (there probably should be central # code for this somewhere, as this is done in taprender and # possibly in other places, too) if segments and not segments[-1]: # trailing slashes are forbidden here newSegments = "/".join(segments[:-1]) if newSegments: newSegments = "/" + newSegments raise svcs.WebRedirect( self.service.getURL(self.name) + newSegments) uwsactions.lowercaseProtocolArgs(inevow.IRequest(ctx).args) return asyncrender.getAsyncResource(ctx, self.workerSystem, self.name, self.service, segments), ()
def locateChild(self, ctx, segments): if len(segments) == 1 and not segments[0]: return self, () if self.staticPath is None: raise svcs.ForbiddenURI("No static data on this service") relPath = "/".join(segments) destName = os.path.join(self.staticPath, relPath) if os.path.isdir(destName): if not destName.endswith("/"): raise svcs.WebRedirect(inevow.IRequest(ctx).uri + "/") return static.File(destName).directoryListing(), () elif os.path.isfile(destName): return ifpages.StaticFile(destName, self.rd), () else: raise svcs.UnknownURI("No %s available here." % relPath)
def renderHTTP(self, ctx): # The root resource redirects to an info on TAP raise svcs.WebRedirect(self.service.getURL("info", absolute=False))
def renderHTTP(self, ctx): raise svcs.WebRedirect(self.pr["accessPath"])
def locateChild(self, ctx, segments): rdId = "/".join(segments) if not rdId: raise svcs.WebRedirect("browse") clientRD = base.caches.getRD(rdId) return RDInfoPage(ctx, clientRD), ()