Created
September 3, 2009 10:36
-
-
Save idan/180233 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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