[Web-SIG] [Python-Dev] Adding wsgiref to stdlib

Phillip J. Eby pje at telecommunity.com
Fri Apr 28 22:16:43 CEST 2006

At 02:32 PM 4/28/2006 -0500, Ian Bicking wrote:
>Guido van Rossum wrote:
> > PEP 333 specifies WSGI, the Python Web Server Gateway Interface v1.0;
> > it's written by Phillip Eby who put a lot of effort in it to make it
> > acceptable to very diverse web frameworks. The PEP has been well
> > received by web framework makers and users.
> >
> > As a supplement to the PEP, Phillip has written a reference
> > implementation, "wsgiref". I don't know how many people have used
> > wsgiref; I'm using it myself for an intranet webserver and am very
> > happy with it. (I'm asking Phillip to post the URL for the current
> > source; searching for it produces multiple repositories.)
> >
> > I believe that it would be a good idea to add wsgiref to the stdlib,
> > after some minor cleanups such as removing the extra blank lines that
> > Phillip puts in his code. Having standard library support will remove
> > the last reason web framework developers might have to resist adopting
> > WSGI, and the resulting standardization will help web framework users.
>I'd like to include paste.lint with that as well (as wsgiref.lint or
>whatever).  Since the last discussion I enumerated in the docstring all
>the checks it does.  There's still some outstanding issues, mostly where
>I'm not sure if it is too restrictive (marked with @@ in the source).
>It's at:
>    http://svn.pythonpaste.org/Paste/trunk/paste/lint.py

+1, but lose the unused 'global_conf' parameter and 'make_middleware' 

>I think another useful addition would be some prefix-based dispatcher,
>similar to paste.urlmap (but probably a bit simpler):

I'd rather see something a *lot* simpler - something that just takes a 
dictionary mapping names to application objects, and parses path segments 
using wsgiref functions.  That way, its usefulness as an example wouldn't 
be obscured by having too many features.  Such a thing would still be quite 
useful, and would illustrate how to do more sophisticated 
dispatching.  Something more or less like:

     from wsgiref.util import shift_path_info

     # usage:
     #    main_app = AppMap(foo=part_one, bar=part_two, ...)

     class AppMap:
         def __init__(self, **apps):
             self.apps = apps

         def __call__(self, environ, start_response):
             name = shift_path_info(environ)
             if name is None:
                 return self.default(environ, start_response)
             elif name in self.apps:
                 return self.apps[name](environ,start_response)
             return self.not_found(environ, start_response)

         def default(self, environ, start_response):
             self.not_found(environ, start_response)

         def not_found(self, environ, start_response):
             # code to generate a 404 response here

This should be short enough to highlight the concept, while still providing 
a few hooks for subclassing.

More information about the Web-SIG mailing list