[Web-SIG] Comments/stylistic ideas regarding WSGI

angryhicKclown at netscape.net angryhicKclown at netscape.net
Mon Aug 23 06:44:47 CEST 2004

Now that I understand what WSGI is intended to be used for, I like it a lot. However, I do have a few suggestions.

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.

Finally, I think the most important reason this change should be implemented is because it allows the interface to be easily upgraded without breaking compatibility with older versions. Perhaps (just an example), in the future, there will be a need for a flush() method, in addition to the write() method. In the current version, start_response() would return a tuple of write() and flush(), which would break current compatibility. The only other way I see of doing this using the current spec would be passing a default parameter of the version of the API used, which is ugly. With this enhancement I propose, it is simply a means of adding a method to the gateway parameter.

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

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

Any comments/criticisms are appreciated.

Switch to Netscape Internet Service.
As low as $9.95 a month -- Sign up today at http://isp.netscape.com/register

Netscape. Just the Net You Need.

New! Netscape Toolbar for Internet Explorer
Search from anywhere on the Web and block those annoying pop-ups.
Download now at http://channels.netscape.com/ns/search/install.jsp

More information about the Web-SIG mailing list