[Web-SIG] Comments/stylistic ideas regarding WSGI

Jim Dabell jim-web-sig at jimdabell.com
Mon Aug 23 07:30:06 CEST 2004

On Monday 23 August 2004 05:44, angryhicKclown at netscape.net wrote:
> Although it means more typing, I think the API is too cryptic as-is. I
> think that applications should be callable, but should have a single
> parameter: gateway. The gateway parameter contains attributes and methods
> such as environ, start_response(), and write(). This way, it's clear to the
> end-user both in documentation (removing many instances of "callable" and
> confusion with __init__) and also is very much more natural to many
> programmers.

That's the first thing I thought when skimming the draft.  Why bother moving 
tuples around when you can organise the relevent information into an object 
and simply send that around instead?  It's less to keep track of, and an 
easily extendable interface.

> 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')

That's starting to look a lot like a mod_python handler.

My only other comment for the time being is that if the status argument to the 
start_response function was changed to an integer instead of a string, it 
would be marginally easier to compare and branch on.  A custom "reason 
phrase" that comes after the integer in the response status line can be 
provided by other means, perhaps gateway.reason_phrase, if desired.

Jim Dabell

More information about the Web-SIG mailing list