Skip to content

Instantly share code, notes, and snippets.

@inklesspen
Created June 21, 2010 15:40
Show Gist options
  • Select an option

  • Save inklesspen/447035 to your computer and use it in GitHub Desktop.

Select an option

Save inklesspen/447035 to your computer and use it in GitHub Desktop.
import inspect
def restrict(**parameters):
def wrapper(func, self, *args, **kwargs):
spec = inspect.getargspec(func)
# since we're assuming self will be the first argument, just take it out here
args_spec = spec.args
args_spec.pop(0)
copy_kwargs = kwargs.copy()
for arg_pair in zip(args_spec, args):
copy_kwargs[arg_pair[0]] = arg_pair[1]
log.debug(repr(copy_kwargs.keys()))
return func(self, *args, **kwargs)
return decorator(wrapper)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment