呼び出しを認証するためのデコレータを作成しました。引数が1つしかない場合は正常に機能しますが、引数が1つを超えると機能せず、。がトリガーされますinner() takes exactly 1 argument (2 given)
。トルネードを使用しているので、コールバックスパゲッティが少しありますが、これを行うための最良の方法がわかりません。
#this works
class FirstHandler(BaseHandler):
@asynchronous
@oauth_machine.auth
def post(self):
print self.user
self.finish()
#this now also does
class SecondHandler(BaseHandler):
@asynchronous
@oauth_machine.auth
def get(self, args):
self.write("ok")
self.finish()
デコレータ関数
def auth(fn):
def inner(self, *args):
res = get_user_by_credentials(self, fn, args, callback=done_auth)
return inner
def get_user_by_credentials(self, fn, callback):
def onFetchUserCredentials(result, error):
self.user = result
callback(self, fn, args)
email = self.get_argument("email")
password = self.get_argument("password")
settings.DB.users.find_one({'email': email, 'password': password }, callback=onFetchUserCredentials)
def done_auth(result, fn, args):
return fn(result, args)
編集 :
コードを動作バージョンに更新しました。
ありがとう!