[Web-SIG] Comments/stylistic ideas regarding WSGI

Ian Bicking ianb at colorstudy.com
Mon Aug 23 07:24:29 CEST 2004


angryhicKclown at netscape.net wrote:
> Here's the example as it is now:
> 
>      def simple_app(environ, start_response):
>          """Simplest possible application object"""
>          status = '200 OK'
>          headers = [('Content-type','text/plain')]
>          write = start_response(status, headers)
>          write('Hello world!\n')
> 
> With my enhancements, it would now look like:
> 
>     def simple_app(gateway):
>         status = '200 OK'
>         headers = [('Content-type','text/plain')]
>         gateway.start_response(status, headers)
>         gateway.write('Hello world!\n')

That does look easier to understand.  There'd be no particular reason to 
put the input stream inside the environ dictionary either.  I assume it 
would simply be an error to use gateway.write before start_response.

> In my opinion, my proposal looks a bit clearer.
> 
> My other idea (which follows the previous proposal) is to scrap start_response() entirely, and instead set gateway.status and gateway.headers attributes. The simple app would now look like:
> 
>     def simple_app(gateway):
>         gateway.status = '200 OK'
>         gateway.headers = [('Content-type','text/plain')] # perhaps gateway.set_header('Content-type','text/plain')?
>         gateway.write('Hello world!\n')

This is harder to implement and understand.  start_response is likely to 
be an actual action on the part of the gateway, with this model you'd 
have to detect when both status and headers were set, or on the first 
call to write, or something like that.  I think an explicit 
start_response is the best idea, whether a method or function.

-- 
Ian Bicking  /  ianb at colorstudy.com  / http://blog.ianbicking.org


More information about the Web-SIG mailing list