Skip to content

Instantly share code, notes, and snippets.

@honmaple
Created October 12, 2016 02:15
Show Gist options
  • Save honmaple/7f0e6859fa86d0444a4b70b2e3365515 to your computer and use it in GitHub Desktop.
Save honmaple/7f0e6859fa86d0444a4b70b2e3365515 to your computer and use it in GitHub Desktop.
restful形式的权限管理 based on flask
class RestfulBase(object):
decorators = ()
def __call__(self, func):
f = self.method(func)
if self.decorators:
for dec in reversed(self.decorators):
f = dec(f)
return f
def method(self, func):
@wraps(func)
def decorator(*args, **kwargs):
meth = getattr(self, request.method.lower(), None)
if request.method == 'HEAD':
meth = getattr(self, 'get', None)
if meth is not None:
check = meth(*args, **kwargs)
if check:
return self.callback()
return func(*args, **kwargs)
return decorator
def callback(self):
abort(403)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment