[Python-Dev] [Web-SIG] Adding wsgiref to stdlib (original) (raw)

Guido van Rossum guido at python.org
Fri Apr 28 22:19:26 CEST 2006


It still looks like an application of WSGI, not part of a reference implementation. Multiple apps looks like an advanced topic to me; more something that the infrastructure (Apache server or whatever) ought to take care of.

I don't expect you to agree with me. But I don't expect you to be able to convince me either. Maybe you can convince Phillip; I'm going to try to sit on my hands now.

--Guido

On 4/28/06, Ian Bicking <ianb at colorstudy.com> wrote:

Guido van Rossum wrote: >> 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 > > > IMO this is getting into framework design. Perhaps something like this > could be added in 2.6?

I don't think it's frameworky. It could be used to build a very primitive framework, but even then it's not a particularly useful starting point. In Paste this would generally be used below any framework (or above I guess, depending on which side is "up"). You'd pass /blog to a blog app, /cms to a cms app, etc. WSGI already is very specific about what needs to be done when doing this dispatching (adjusting SCRIPTNAME and PATHINFO), and that's all that the dispatching needs to do. The applications themselves are written in some framework with internal notions of URL dispatching, but this doesn't infringe upon those. (Unless the framework doesn't respect SCRIPTNAME and PATHINFO; but that's their problem, as the dispatcher is just using what's already allowed for in the WSGI spec.) It also doesn't overlap with frameworks, as prefix-based dispatching isn't really that useful in a framework. The basic implementation is: class PrefixDispatch(object): def init(self): self.applications = {} def addapplication(self, prefix, app): self.applications[prefix] = app def call(self, environ, startresponse): apps = sorted(self.applications.items(), key=lambda x: -len(x[0])) pathinfo = environ.get('PATHINFO', '') for prefix, app in apps: if not pathinfo.startswith(prefix): continue environ['SCRIPTNAME'] = environ.get('SCRIPTNAME', '')+prefix environ['PATHINFO'] = environ.get('PATHINFO', '')[len(prefix):] return app(environ, startresponse) startresponse('404 Not Found', [('Content-type', 'text/html')]) return ['

Not Found

']

There's a bunch of checks that should take place (most related to /'s), and the not found response should be configurable (probably as an application that can be passed in as an argument). But that's most of what it should do. -- Ian Bicking / ianb at colorstudy.com / http://blog.ianbicking.org

-- --Guido van Rossum (home page: http://www.python.org/~guido/)



More information about the Python-Dev mailing list