本文整理汇总了Python中gratipay.security.user.User.from_id方法的典型用法代码示例。如果您正苦于以下问题:Python User.from_id方法的具体用法?Python User.from_id怎么用?Python User.from_id使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类gratipay.security.user.User
的用法示例。
在下文中一共展示了User.from_id方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _get_user_via_basic_auth
# 需要导入模块: from gratipay.security.user import User [as 别名]
# 或者: from gratipay.security.user.User import from_id [as 别名]
def _get_user_via_basic_auth(auth_header):
"""Given a basic auth header, return a User object.
"""
try:
creds = binascii.a2b_base64(auth_header[len('Basic '):]).split(':', 1)
except binascii.Error:
raise Response(400, 'Malformed "Authorization" header')
if len(creds) != 2:
raise Response(401)
userid, api_key = creds
if len(userid) == 36 and '-' in userid:
user = _get_user_via_api_key(userid) # For backward-compatibility
else:
try:
userid = int(userid)
except ValueError:
raise Response(401)
user = User.from_id(userid)
if user.ANON or not constant_time_compare(user.participant.api_key, api_key):
raise Response(401)
return user
示例2: test_user_can_be_loaded_from_id
# 需要导入模块: from gratipay.security.user import User [as 别名]
# 或者: from gratipay.security.user.User import from_id [as 别名]
def test_user_can_be_loaded_from_id(self):
alice = self.make_participant('alice')
actual = User.from_id(alice.id).participant.username
assert actual == 'alice'
示例3: test_user_from_None_id_is_anonymous
# 需要导入模块: from gratipay.security.user import User [as 别名]
# 或者: from gratipay.security.user.User import from_id [as 别名]
def test_user_from_None_id_is_anonymous(self):
user = User.from_id(None)
assert user.ANON
示例4: test_user_from_bad_id_is_anonymous
# 需要导入模块: from gratipay.security.user import User [as 别名]
# 或者: from gratipay.security.user.User import from_id [as 别名]
def test_user_from_bad_id_is_anonymous(self):
user = User.from_id(1786541)
assert user.ANON