Created
October 12, 2016 02:15
-
-
Save honmaple/7f0e6859fa86d0444a4b70b2e3365515 to your computer and use it in GitHub Desktop.
restful形式的权限管理 based on flask
This file contains hidden or 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
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