On Fri, Aug 22, 2003 at 06:47:41PM +0400, Oleg Broytmann wrote:
> On Thu, Aug 21, 2003 at 11:45:16AM -0400, Graham Fawcett wrote:
> > if hasattr(output, '__iter__'):
>
> if hasattr(output, 'next'), of course :)
I would prefer a more exact test. There could be code out there now
that returns an object that has a 'next' attribute and expects str() to
be called on it before sending it as the response.
How about this:
# in http_response.py
class Stream:
def __init__(self, iterable, length=None):
self.iterable = iterable
self.length = length
Then in publisher, use isinstance(output, Stream). If 'length' is
defined then Content-Length is set using it (e.g. when streaming a
static file from disk).
Neil