5 messages in com.googlegroups.pylons-discussRe: Custom publisher and controller
FromSent OnAttachments
Damjan28 Jan 2007 19:56 
Ian Bicking29 Jan 2007 10:27 
Ben Bangert29 Jan 2007 11:07 
Ian Bicking29 Jan 2007 11:20 
Damjan31 Jan 2007 04:53 
Subject:Re: Custom publisher and controller
From:Ian Bicking (ianb@public.gmane.org)
Date:01/29/2007 11:20:57 AM
List:com.googlegroups.pylons-discuss

Ben Bangert wrote:

Now, I've created a working proof of concept WSGI compatible implementation, but I'm wandering how to integrate it with pylons. The thing is I'd like to reuse pylons session, caching, authkit, database etc. handling, input validation, so that I don't have to do it myself :).

For a first step, try dropping such a WSGI app into a controller. Pylons will attempt to instantiate controller classes if they're a subclass of WSGIController, otherwise it will assume the class is a valid WSGI app and merely call it (standard WSGI call). If your class is a wrapped in something that makes it a standard WSGI app, then merely dropping it in with the proper controller name in a controller module will do the trick.

The WSGIController test seems kind of inflexible. It would be nice if there was a test that didn't depend on a specific class (though WSGIController might actually be the easiest starting place for Damjan).

Just testing isinstance(app, (types.ClassType, type)) might be a good test to see if you need to instantiate. Generally classes aren't WSGI apps. In theory they can be, but I've never actually seen someone do that -- it's kind of lame, and a function is generally easier.

Another option is looking for .wsgi_application and using that. One can make a descriptor which will instantiate the containing class if necessary (but not instantiate it if not necessary).