Skip to content

Instantly share code, notes, and snippets.

@idan
Created September 3, 2009 10:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save idan/180233 to your computer and use it in GitHub Desktop.
Save idan/180233 to your computer and use it in GitHub Desktop.
#The decorated method's signature:
def read(self, request, band_id=None, slug=None)
#The original decorator:
def argcheck(fn_arg, get_param, argtype=None, required=True):
def wrap(f):
def decorated(self, request, *args, **kwargs):
arg = kwargs.get(fn_arg, None)
param = request.GET.get(get_param, arg)
# do stuff
return f(self, request, *args, **kwargs)
return decorated
return wrap
# now using @decorator:
def argcheck(fn_arg, get_param, argtype=None, required=True):
@decorator
def wrap(f, self, request, *args, **kwargs):
# uh oh, kwargs are empty
# whatever was in kwargs is now in args
arg = kwargs.get(fn_arg, None) # and this is where the shit
hits the fan
param = request.GET.get(get_param, arg)
# do stuff
return f(self, request, *args, **kwargs)
return wrap
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment