On Jan 4, 2007, at 5:06 AM, Ian Bicking wrote:
"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.
I wasn't planning on making every controller method a wsgi app on
it's own, only the controller itself (more or less like in http://
paste.turbogears.org/paste/771).
However, this surely looks interesting because current tg decorators
like "require" could be implemented as middleware under the scenes...
I'd have to play with this idea....
Thanks :)
Alberto
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---