I am trying to get a local variable from a decorator. Example:
def needs_privilege(privilege, project=None):
"""Check whether the logged-in user is authorised based on the
given privilege
@type privilege: Privilege object, id, or str
@param privilege: The requested privilege"""
def validate(func, self, *args, **kwargs):
"""Validator of needs_privillige"""
try: check(self.user, privilege, project)
except AccessDenied:
return abort(status_code=401)
else:
return func(self, *args, **kwargs)
return decorator(validate)
After registration of the function, for example:
@needs_privilege("some_privilege")
def some_function():
pass
I would like to get the 'privilige' variable (which uses validate ()) from some_function. After searching for more than one hour, I feel pretty lost. Is it possible?
Edit : Let me describe my problem in more detail: can I get the string "some_prvilege" without executing some_function? Sort of:
a = getattr(module, 'somefunction')
print a.decorator_arguments
? Thanks for helping me so far!
source
share