def render(self): """ Renders the requested resource returned from the self.process() method. """ # traverse the resource tree child = getChildForRequest(self.env.tree, self) # check result and either render direct or in thread if IFileSystemResource.providedBy(child): # render direct return child.render(self) elif IStatical.providedBy(child): # render direct return child.render(self) elif IScriptResource.providedBy(child): msg = "Script resources may not be called via SFTP." raise ForbiddenError(msg) elif IRESTResource.providedBy(child): return child.render(self) elif IResource.providedBy(child): return child.render(self) msg = "I don't know how to handle this resource type %s" raise InternalServerError(msg % type(child))
else: return self._renderFileResource(data) elif IStatical.providedBy(result): # static resources render direct data = result.render(self) if isinstance(data, basestring): return self._renderResource(data) elif isinstance(data, dict): return self._renderFolder(data) elif IRESTResource.providedBy(result): # REST resource render in thread d = threads.deferToThread(result.render, self) d.addCallback(self._cbSuccess) d.addErrback(self._cbFailed) return server.NOT_DONE_YET elif IResource.providedBy(result): # all other resources render in thread d = threads.deferToThread(result.render, self) d.addCallback(self._cbSuccess) d.addErrback(self._cbFailed) return server.NOT_DONE_YET msg = "I don't know how to handle this resource type %s" raise InternalServerError(msg % type(result)) def _cbSuccess(self, result): if isinstance(result, dict): # a folderish resource return self._renderFolder(result) elif isinstance(result, basestring): # already some textual result return self._renderResource(result)