Beispiel #1
0
    def _formatOutput(self, res, ctx):
        """actually delivers the whole document.

		This is basically nevow's rend.Page._renderHTTP, changed to
		provide less blocks.
		"""
        request = inevow.IRequest(ctx)

        if isinstance(res.original, tuple):
            # core returned a complete document (mime and string)
            mime, payload = res.original
            request.setHeader("content-type", mime)
            request.setHeader(
                'content-disposition',
                'attachment; filename=result%s' % common.getExtForMime(mime))
            return streaming.streamOut(lambda f: f.write(payload), request)

        self.result = res
        if "response" in self.service.templates:
            self.customTemplate = self.service.getTemplate("response")

        ctx = context.PageContext(parent=ctx, tag=self)
        self.rememberStuff(ctx)
        doc = self.docFactory.load(ctx)
        ctx = context.WovenContext(ctx, T.invisible[doc])

        return deliverYielding(doc, ctx, request)
Beispiel #2
0
    def _formatOutput(self, data, ctx):
        data.original.addMeta("info",
                              "",
                              infoName="QUERY_STATUS",
                              infoValue="OK")

        request = inevow.IRequest(ctx)
        if "RESPONSEFORMAT" in request.args:
            # This is our DALI RESPONSEFORMAT implementation; to declare
            # this, use <STREAM source="//pql#RESPONSEFORMAT"/>
            # in the service body.
            destFormat = request.args["RESPONSEFORMAT"][0]
            request.setHeader("content-type",
                              formats.getMIMEFor(destFormat, destFormat))

            # TBD: format should know extensions for common formats
            request.setHeader('content-disposition',
                              'attachment; filename="result.dat"')

            def writeStuff(outputFile):
                formats.formatData(destFormat,
                                   data.original,
                                   outputFile,
                                   acquireSamples=False)

            return streaming.streamOut(writeStuff, request)

        else:
            # default behaviour: votable.
            request.setHeader('content-disposition',
                              'attachment; filename="votable.xml"')
            request.setHeader("content-type", self.resultType)
            return streaming.streamVOTable(request, data)
Beispiel #3
0
	def _streamOutTar(self, productData, request, queryMeta):
		name, mime = self._getHeaderVals(queryMeta)
		request.setHeader('content-disposition', 
			'attachment; filename=%s'%name)
		request.setHeader("content-type", mime)

		def writeTar(dest):
			self._productsToTar(productData, dest)
		return streaming.streamOut(writeTar, request)
Beispiel #4
0
    def renderHTTP(self, ctx):
        request = inevow.IRequest(ctx)
        request.setHeader("content-type", "text/plain")

        def writeNoise(f):
            f.buffer.chunkSize = 30
            f.write(
                "Here is some data. (and some more, just to cause a flush)\n")
            raise Exception

        return streaming.streamOut(writeNoise, request)
Beispiel #5
0
    def _formatOutput(cls, data, ctx):
        request = inevow.IRequest(ctx)
        request.setHeader("content-type", "text/plain")

        def produceData(destFile):
            formats.formatData("txt",
                               data.original,
                               request,
                               acquireSamples=False)

        return streaming.streamOut(produceData, request)
Beispiel #6
0
 def _formatOutput(self, data, ctx):
     request = inevow.IRequest(ctx)
     if isinstance(data.original, tuple):
         # core returned a complete document (mime and string)
         mime, payload = data.original
         request.setHeader("content-type", mime)
         return streaming.streamOut(lambda f: f.write(payload), request)
     else:
         request.setHeader("content-type", "text/xml+votable")
         data.original.setMeta("_type", "results")
         data.original.getPrimaryTable().votCasts = self._outputTableCasts
         return DALRenderer._formatOutput(self, data, ctx)
Beispiel #7
0
    def renderHTTP(self, ctx):
        request = inevow.IRequest(ctx)
        dataSize = int(request.args.get("size", [300])[0])
        chunkSize = int(request.args.get("chunksize", [1000])[0])

        def writeNoise(f):
            for i in range(dataSize / chunkSize):
                f.write("x" * chunkSize)
            lastPayload = "1234567890"
            toSend = dataSize % chunkSize
            f.write(lastPayload * (toSend / 10) + lastPayload[:toSend % 10])

        return streaming.streamOut(writeNoise, request)
Beispiel #8
0
    def _formatOutput(cls, data, ctx):
        request = inevow.IRequest(ctx)
        request.setHeader('content-disposition',
                          'attachment; filename=table.json')
        request.setHeader("content-type", "application/json")

        def produceData(destFile):
            formats.formatData("json",
                               data.original,
                               request,
                               acquireSamples=False)

        return streaming.streamOut(produceData, request)
Beispiel #9
0
    def _formatOutput(cls, data, ctx):
        request = inevow.IRequest(ctx)
        request.setHeader('content-disposition',
                          'attachment; filename=table.csv')
        request.setHeader("content-type", "text/csv;header=present")

        def produceData(destFile):
            formats.formatData("csv_header",
                               data.original,
                               request,
                               acquireSamples=False)

        return streaming.streamOut(produceData, request)
Beispiel #10
0
    def _formatResult(self, res, ctx):
        request = inevow.IRequest(ctx)
        f, type = res

        def writeTable(outputFile):
            utils.cat(f, outputFile)

        request.setHeader("content-type", str(type))
        # if request has an accumulator, we're testing.
        if hasattr(request, "accumulator"):
            writeTable(request)
            return ""
        else:
            return streaming.streamOut(writeTable, request)
Beispiel #11
0
    def _formatData(self, svcResult, request):
        # the core returns mime, data or a resource.  So, if it's a pair,
        # to something myself, else let twisted sort it out
        data = svcResult.original

        if isinstance(data, tuple):
            # XXX TODO: the same thing is in formrender.  Refactor; since this is
            # something most renderers should be able to do, ServiceBasedPage would be
            # a good place
            mime, payload = data
            request.setHeader("content-type", mime)

            if self.attachResult:
                request.setHeader(
                    'content-disposition', 'attachment; filename=result%s' %
                    common.getExtForMime(mime))

            return streaming.streamOut(lambda f: f.write(payload), request)

        else:
            return data
 def renderHTTP(self, ctx):
     request = inevow.IRequest(ctx)
     request.setHeader("content-type", "image/fits")
     return streaming.streamOut(self._writeStuffTo, request)