On Tue, Feb 9, 2010 at 1:13 PM, Mike Orr <[email protected]> wrote:
> The problem is that an autonomous function has no access to the WSGI
> data except via its arguments. A middleware could put some kind of
> multipurpose helper object in the environ, but then you'd be dealing
> with methods of some huge helper object, not autonomous functions.
Oh, I was going to mention the other way. I aluded to it before.
class SecureForm(object):
def __init__(self, get_cookie_func, set_cookie_func):
"""User must provide callbacks:
``get_cookie(name) => value``
``set_cookie(name, value)``
"""
self.get_cookie = get_cookie
self.set_cookie = set_cookie
def __call__(self, form_token_args...):
cookie = self.get_cookie(form_token_key)
...
Then you can instantiate it in helpers.py:
from pylons import request, response
def _set_cookie(key, value):
response.set_cookie(key, value, kw1=value1, ...)
secure_form = SecureForm(
request.cookies.__getitem__,
_set_cookie)
That way the helper can be framework neutral but Pylons can customize
it. Or you can do the equivalent with subclassing. I was trying to
provide a general layer to do this for all helpers, but there just
wasn't a lot of places where it would be used, and most users do have
Pylons, and it would have required a bunch of testing. But for a
specific helper, it's not that much work.
--
Mike Orr <[email protected]>
--
You received this message because you are subscribed to the Google Groups
"pylons-discuss" 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/pylons-discuss?hl=en.