"Every TG controller will be effectively be a WSGI app of it's own. On a
low level, this means that controllers will have a __call__ method that
follows the WSGI protocol. This method could be overriden to provide any
sort of dispatching you dream of."
Without advocating anything in particular, one convention I've used with
this is to use an attribute instead of __call__ directly. For example:
# Calls func(req), not func(**params), but you'll get the point...
def simple_expose(func):
def wsgi_application(environ, start_response):
start_response('200 OK', [('content-type', 'text/html')])
return func(paste.wsgiwrappers.WSGIRequest(environ))
func.wsgi_application = wsgi_application
return func
Then the dispatcher, when it gets to the terminal object (at least
terminal as far as it is concerned) checks for hasattr(obj,
'wsgi_application'), and uses that instead. This way the signature is
unaffected, and by being a little clever you could stack middleware
using a decorator as well. A possible downside is that the function
when accessed directly doesn't have any of those filters applied; which
is sometimes what you want, and sometimes not. (E.g., an authorization
decorator could go either way.) Not that you can't decorate the
function and decorate .wsgi_application at the same time.
--
Ian Bicking | [EMAIL PROTECTED] | http://blog.ianbicking.org
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"TurboGears Trunk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/turbogears-trunk?hl=en
-~----------~----~----~----~------~----~------~--~---