本文整理匯總了Python中www.models.User.find方法的典型用法代碼示例。如果您正苦於以下問題:Python User.find方法的具體用法?Python User.find怎麽用?Python User.find使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類www.models.User
的用法示例。
在下文中一共展示了User.find方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: cookie2user
# 需要導入模塊: from www.models import User [as 別名]
# 或者: from www.models.User import find [as 別名]
def cookie2user(cookie_str):
'''
Parse cookie and load user if cookie is valid.
'''
if not cookie_str:
return None
try:
L = cookie_str.split('-')
if len(L) != 3:
return None
uid, expires, sha1 = L
if int(expires) < time.time():
return None
user = yield from User.find(uid)
if user is None:
return None
s = '%s-%s-%s-%s' % (uid, user.passwd, expires, _COOKIE_KEY)
if sha1 != hashlib.sha1(s.encode('utf-8')).hexdigest():
logging.info('invalid sha1')
return None
user.passwd = '******'
return user
except Exception as e:
logging.exception(e)
return None
示例2: find_model
# 需要導入模塊: from www.models import User [as 別名]
# 或者: from www.models.User import find [as 別名]
def find_model(model, id):
if model == 'blog':
blog = yield from Blog.find(id)
return blog
if model == 'user':
user = yield from User.find(id)
return user
if model == 'comment':
comment = yield from Comment.find(id)
return comment