Beispiel #1
0
 def setBody(self, body, title='', is_error=0):
     if isinstance(body, file) or IStreamIterator.providedBy(body):
         body.seek(0, 2)
         length = body.tell()
         body.seek(0)
         self.setHeader('Content-Length', '%d' % length)
         self.body = body
     else:
         HTTPResponse.setBody(self, body, title, is_error)
 def setBody(self, body, title='', is_error=0):
     if isinstance(body, file) or IStreamIterator.providedBy(body):
         body.seek(0, 2)
         length = body.tell()
         body.seek(0)
         self.setHeader('Content-Length', '%d' % length)
         self.body = body
     else:
         HTTPResponse.setBody(self, body, title, is_error)
Beispiel #3
0
 def setBody(self, body, title='', is_error=0, **kw):
     """ Accept either a stream iterator or a string as the body """
     if IStreamIterator.providedBy(body):
         assert (self.headers.has_key('content-length'))
         # wrap the iterator up in a producer that medusa can understand
         self._bodyproducer = iterator_producer(body)
         HTTPResponse.setBody(self, '', title, is_error, **kw)
         return self
     else:
         HTTPResponse.setBody(self, body, title, is_error, **kw)
Beispiel #4
0
 def setBody(self, body, title='', is_error=0, **kw):
     """ Accept either a stream iterator or a string as the body """
     if IStreamIterator.isImplementedBy(body):
         assert(self.headers.has_key('content-length'))
         # wrap the iterator up in a producer that medusa can understand
         self._bodyproducer = iterator_producer(body)
         HTTPResponse.setBody(self, '', title, is_error, **kw)
         return self
     else:
         HTTPResponse.setBody(self, body, title, is_error, **kw)
Beispiel #5
0
    def setBody(self, body, title='', is_error=False, lock=None):
        # allow locking of the body in the same way as the status
        if self._locked_body:
            return

        if isinstance(body, IOBase):
            body.seek(0, 2)
            length = body.tell()
            body.seek(0)
            self.setHeader('Content-Length', '%d' % length)
            self.body = body
        elif IStreamIterator.providedBy(body):
            self.body = body
            HTTPResponse.setBody(self, b'', title, is_error)
        elif IUnboundStreamIterator.providedBy(body):
            self.body = body
            self._streaming = 1
            HTTPResponse.setBody(self, b'', title, is_error)
        else:
            HTTPResponse.setBody(self, body, title, is_error)

        # Have to apply the lock at the end in case the super class setBody
        # is called, which will observe the lock and do nothing
        if lock:
            self._locked_body = 1
Beispiel #6
0
 def setBody(self, body, title='', is_error=0, **kw):
     """ Accept either a stream iterator or a string as the body """
     if not IStreamIterator.providedBy(body):
         return HTTPResponse.setBody(self, body, title, is_error, **kw)
     assert not self._wrote
     if isinstance(body, BlobStreamIterator):
         body = body.blob # A BlobFile
     if hasattr(body, 'seek') and hasattr(body, 'read') and hasattr(body, 'close'):
         self.stdout = body
         self._wrote = 1
         return
     try:
         while True:
             chunk = body.next()
             self.write(chunk)
     except StopIteration:
         pass
Beispiel #7
0
 def setBody(self, body, title='', is_error=0, **kw):
     """ Accept either a stream iterator or a string as the body """
     if not IStreamIterator.providedBy(body):
         return HTTPResponse.setBody(self, body, title, is_error, **kw)
     assert not self._wrote
     if isinstance(body, BlobStreamIterator):
         body = body.blob  # A BlobFile
     if hasattr(body, 'seek') \
        and hasattr(body, 'read') and \
        hasattr(body, 'close'):
         self.stdout = body
         self._wrote = 1
         return
     try:
         while True:
             chunk = body.next()
             self.write(chunk)
     except StopIteration:
         pass