Beispiel #1
0
 def write(self, output):
     # Called in application thread
     from twisted.internet import reactor
     if self.response is None:
         raise RuntimeError(
             "Application didn't call startResponse before writing data!")
     if not self.headersSent:
         self.stream=self.response.stream=stream.ProducerStream()
         self.headersSent = True
         
         # threadsafe event object to communicate paused state.
         self.unpaused = threading.Event()
         
         # After this, we cannot touch self.response from this
         # thread any more
         def _start():
             # Called in IO thread
             self.stream.registerProducer(self, True)
             self.__callback()
             # Notify application thread to start writing
             self.unpaused.set()
         reactor.callFromThread(_start)
     # Wait for unpaused to be true
     self.unpaused.wait()
     reactor.callFromThread(self.stream.write, output)
Beispiel #2
0
 def __init__(self, request):
     from ipython1.external.twisted.web2 import http
     components.Componentized.__init__(self)
     self.request = request
     self.response = http.Response(stream=stream.ProducerStream())
     # This deferred will be fired by the first call to write on OldRequestAdapter
     # and will cause the headers to be output.
     self.deferredResponse = defer.Deferred()
Beispiel #3
0
 def writeAll(self, result):
     # Called in application thread
     from twisted.internet import reactor
     if not self.headersSent:
         if self.response is None:
             raise RuntimeError(
                 "Application didn't call startResponse before writing data!")
         l = 0
         for item in result:
             l += len(item)
         self.response.stream=stream.ProducerStream(length=l)
         self.response.stream.buffer = list(result)
         self.response.stream.finish()
         reactor.callFromThread(self.__callback)
     else:
         # Has already been started, cannot replace the stream
         def _write():
             # Called in IO thread
             for s in result:
                 self.stream.write(s)
             self.stream.finish()
         reactor.callFromThread(_write)
Beispiel #4
0
 def __init__(self, request, deferred):
     self.request = request
     self.deferred = deferred
     self.stream = stream.ProducerStream()
     self.response = http.Response(stream=self.stream)
Beispiel #5
0
    def createRequest(self):
        self.stream = stream_mod.ProducerStream(self.length)
        self.response = http.Response(self.code, self.inHeaders, self.stream)
        self.stream.registerProducer(self, True)

        del self.inHeaders