On 9/11/07, Ben Bangert <[EMAIL PROTECTED]> wrote:
> On Sep 11, 2007, at 9:13 AM, Chris AtLee wrote:
>
> > The first is that using abort() from a generator method doesn't seem
> > to be caught properly by pylons (or maybe paste) so instead of the
> > client getting a 404 error, he sees a "Server Error" page (HTTP status
> > 200).
>
> Correct, you can't abort in a generator. Technically, when you return
> a generator, Pylons wraps up shop, and the generator passes fully out
> of the Pylons middleware as it is then used by the WSGI server. When
> abort is actually called, there is no middleware then to catch the
> aborted exception and handle it.
Ok, this explains why I've been having these problems using generators.
> On top of that, there's also the violation of the WSGI spec in this
> case, since you returned a response (which the response is set to
> status code 200), then you're trying to change it *After* its already
> started sending data to the client. This just won't work. You can't
> send data to the client then change your mind in the middle (after
> sending a status code 200) that its then going to be a 404.
This is a bit counter-intuitive. The controller method looks like this:
abort(404)
yield "Hello World"
At first glance it appears that I am aborting with a 404 before returning
any data, so it doesn't look like I'm changing my mind about what I'm
sending to the client. But since I have a yield statement in my method,
Python returns a generator object for the method instead of running the
code right away when called. This causes problems down the line since the
generator object is returned out of Pylons' control.
> In the future, I think the HTTP spec might allow such a thing, I
> recall reading about something like that, but at the moment its a no-
> go. Returning generators should be used purely for streaming large
> data sets when you already know its not a 404.
Is response.write a better option then?
Would it be possible for Pylons to detect when a generator is
returned and create a wrapper around it instead of returning it directly to
the WSGI stack so that the Pylons globals and exception handling are
maintained?
Cheers,
Chris
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"pylons-discuss" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/pylons-discuss?hl=en
-~----------~----~----~----~------~----~------~--~---