durusmail: quixote-users: Re: Medusa producers
Medusa producers
2003-08-21
Re: Medusa producers
2003-08-21
2003-08-21
2003-08-21
2003-08-21
2003-08-22
2003-08-22
2003-08-22
2003-08-22
2003-08-22
2003-08-22
response streams [Was: Medusa producers]
response streams
2003-08-27
Re: response streams [Was: Medusa producers]
2003-08-28
Re: Medusa producers
Graham Fawcett
2003-08-21
Oleg Broytmann wrote:
>    Actually, I am going to wrap a generator (FTP traverse) into a producer.
> Something like this:
>
> class iterator_producer:
>    def __init__(self, iterator):
>       self.iterator = iterator
>
>    def more(self):
>       try:
>          return str(self.iteration.next())
>       except StopIteration:
>          return ''
>
>
>>Personally I like the idea, but would want to make sure that it could
>>work correctly with all front ends
>
>
>    It is already impossible, because all handlers set body to str(output).

True, but it wouldn't be too hard to add code in the other handlers that
could consume an iterator and render it to str(output). That's why I
would suggest a layer of indirection: either just a Python iterator, or
a Quixote response subclass.

A non-Medusa handler could do something along the lines of:

     if hasattr(output, '__iter__'):
         # or, if isinstance(output, quixote.DeferedResponse)
         # output is an iterator: consume it
         output = ''.join([x for x in output])
     output = str(output)

meanwhile, medusa_http could use your iterator_producer. This would
prevent a Medusa dependency in your application, which is a Good Thing, IMO.

Just my two cents' worth.

Best,
-- Graham



reply