2005/12/9, Graham Dumpleton <[EMAIL PROTECTED]>:
> Grisha wrote ..
> >
> > On Thu, 8 Dec 2005, Gregory (Grisha) Trubetskoy wrote:
> >
> > >  def index(req)
> > >      req.content_type = 'text/plain'
> > >      yield '1\n'
> > >      yield '2\n'
> > >      yield '3\n'
> > >      yield '4\n'
> > >
> > >  When published, this module should return a text content with
> > > '1\n2\n3\n4\n'.
> > >
> > > ---
> > >
> > > I'd expect this to return '1\n'. Because in my mind one HTTP request
> > > corresponds to one call to the published function?
> >
> > Actually, I take that back. It should return something more along the
> > lines of '<generator object at 0x81ba5ec>'.
> >
> > Does this make sense?
>
> Which is what it used to do before the change was introduced.
>
> As the generator object has an __iter__ method it is being iterated over
> and the result from each item concatenated.
>
> See code:
>
> def publish_object(req, object):
>     if callable(object):
>
>         # To publish callables, we call them an recursively publish the result
>         # of the call (as done by util.apply_fs_data)
>
>         req.form = util.FieldStorage(req, keep_blank_values=1)
>         return publish_object(req,util.apply_fs_data(object, req.form, req=req))
>
>     elif hasattr(object,'__iter__'):
>
>         # To publish iterables, we recursively publish each item
>         # This way, generators can be published
>         result = False
>         for item in object:
>             result |= publish_object(req,item)
>         return result
>
>     else:
>         ....
>

Uh oh looks like I'm the one to blame here. As mentioned on MODPYTHON-15, Graham and I had a little discussion about the potential for infinite generators, and that's all. My bad is to have unilateraly decided to check in the change though it has not been approved by anyone else. I should have look for approval before checkin this in. Sorry.

As you can see from the source code above, reverting to the previous behaviour is quite simple, we only have to comment out the elif hasattr(object,'__iter__'): block.

I quite agree now that mod_python 3.2 should be a big bugfix release, instead of a release with a lot of new bells and whistles. Let's comment this thing out and see if we bring it back later.

Again, sorry for the mess...

Regards,
Nicolas


Reply via email to