Example #1
0
 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))
Example #2
0
            raise
        # set attributes
        try:
            self.attrs.update(result.getMetadata())
        except:
            pass
        if IRESTResource.providedBy(result):
            # some REST resource
            try:
                data = result.render_GET(proc)
            except SeisHubError, e:
                raise SFTPError(FX_FAILURE, e.message)
            except:
                raise
            self.data = StringIO.StringIO(data)
        elif IFileSystemResource.providedBy(result):
            # some file system resource
            self.data = result.open()
        else:
            msg = "I don't know how to handle this resource type %s"
            raise SFTPError(FX_FAILURE, msg % type(result))

    def readChunk(self, offset, length):
        """
        Read from the file.

        If EOF is reached before any data is read, raise EOFError.

        This method returns the data as a string, or a Deferred that is
        called back with same.