Just bumping this up to see if anyone has any ideas, as I have again run up
against this limitation.
The situation I'm in is that I have a number of controller functions which
all accept some arguments in common (for instance, an API key that has to
be checked to allow access to the resource). My natural inclination was to
handle that with a decorator that strips off the arguments in question and
passes the rest along, something like
def check_secret(func):
@functools.wraps(func)
def wrapper(secret, *args, **kwargs):
secret = request.vars.pop('secret')
if not valid_secret(secret):
error_response()
else:
return func(*args, **kwargs)
return wrapper
@service.json
@check_secret
def some_service(real_arg_1, real_arg2):
# whatever
However, this doesn't work. The decorator returns a wrapped function that
accepts only one "real" argument. The service handler reads the argspec
and only passes the "secret" argument.
I could of course write my own system for doing this, but I'd have to
reimplement all of the function-registering that "service" does. It would
be nice if I could just get "service" to pass ALL of the arguments it
receives, not just the ones named in the function argspec. I think this
could actually be done by making service use inspect.getargspec rather than
manually reading co_argcount and so on, which seems much more fragile.
What is the right way to handle this situation, where I want to "factor
out" handling of arguments that are common in different controller
functions?
--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to the Google Groups
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.