On 12 February 2011 03:36, johnm <[email protected]> wrote:
> Hi,
>
> Note: I realize that what I am asking to do violates the wsgi spec.
>
> Is there any way for me to use mod_wsgi and not provide the response
> status and headers via start_response but instead as part of the body
> (all properly formatted, of course)?

What you do in the layers above the WSGI interface is up to you. You
don't need to preserve the WSGI interface up through all layers of
your application. As example, Django is not WSGI throughout. Instead,
Django has a WSGI adapter that maps into its own internal stack. So,
you can do something similar.

FWIW, eliminating start_response() is the essence of what people were
originally wanting to do in WSGI 2.0, although that hasn't progressed
and the waters have been muddied by people subjugating the WSGI 2.0
moniker for there own ends and trying to apply it to quite different
proposals. So, want you are after is an adapter which maps to an
interface akin to what people were originally wanting for WSGI 2.0.
So, something like the following (untested):

  class Adapter(object):
    def __init__(self, application):
      self.application = application
    def __call__(self, environ, start_response):
      status_line, headers, iterable = self.application(environ)
      start_response(status_line, headers)
      return iterable

You would then write your application as:

  def _application(environ):
    return '200 OK', [('Content-Type', 'text/plain')], ['content']

and wrap it so usable as WSGI application:

  application = Adapter(_application)

With a bit of extra work you could ensure the adapter is usable as a
decorator and do something like:

  @make_wsgi_application
  def application(environ):
    return '200 OK', [('Content-Type', 'text/plain')], ['content']

Ie., make_wsgi_application() would be the decorator function that uses
the adapter to wrap your WSGI 2ish application interface to be a WSGI
1.0 application.

Graham

-- 
You received this message because you are subscribed to the Google Groups 
"modwsgi" 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/modwsgi?hl=en.

Reply via email to