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

Ian Bicking ianb at colorstudy.com
Fri Apr 28 22:50:59 CEST 2006


Phillip J. Eby wrote:
>> 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' 
> functions.

Yeah, those are just related to Paste Deploy and wouldn't go in.

>> I think another useful addition would be some prefix-based dispatcher,
>> similar to paste.urlmap (but probably a bit simpler):
>> http://svn.pythonpaste.org/Paste/trunk/paste/urlmap.py
> 
> 
> 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.

That's mostly what I was thinking, though using a full prefix (instead 
of just a single path segment), and the default is the application at 
'', like in my other email.

paste.urlmap has several features I wouldn't propose (like domain and 
port matching, more Paste Deploy stuff, and a proxy object that I should 
probably just delete); I probably should have been more specific. 
URLMap's dictionary interface isn't that useful either.

Another feature that the example in my other email doesn't have is / 
handling, specifically redirecting /something-that-matches to 
/something-that-matches/ (something Apache's Alias doesn't do but should).

Host and port matching is pretty easy to do at the same time, and in my 
experience can be useful to do at the same time, but I don't really care 
if that feature goes in.

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


More information about the Python-Dev mailing list