本文整理汇总了Python中astakosclient.AstakosClient.service_get_usernames方法的典型用法代码示例。如果您正苦于以下问题:Python AstakosClient.service_get_usernames方法的具体用法?Python AstakosClient.service_get_usernames怎么用?Python AstakosClient.service_get_usernames使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类astakosclient.AstakosClient
的用法示例。
在下文中一共展示了AstakosClient.service_get_usernames方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: UserCache
# 需要导入模块: from astakosclient import AstakosClient [as 别名]
# 或者: from astakosclient.AstakosClient import service_get_usernames [as 别名]
class UserCache(object):
"""uuid<->displayname user 'cache'"""
def __init__(self, astakos_url, astakos_token, split=100, logger=None):
if logger is None:
logger = logging.getLogger(__name__)
self.logger = logger
self.astakos = AstakosClient(astakos_url, retry=2, use_pool=True, logger=logger)
self.astakos_token = astakos_token
self.users = {}
self.split = split
assert self.split > 0, "split must be positive"
def fetch_names(self, uuid_list):
total = len(uuid_list)
split = self.split
count = 0
for start in range(0, total, split):
end = start + split
try:
names = self.astakos.service_get_usernames(self.astakos_token, uuid_list[start:end])
count += len(names)
self.users.update(names)
except AstakosClientException:
pass
except Exception as err:
self.logger.error("Unexpected error while fetching " "user display names: %s" % repr(err))
diff = total - count
assert diff >= 0, "fetched more displaynames than requested"
if diff:
self.logger.debug("Failed to fetch %d displaynames", diff)
def get_uuid(self, name):
uuid = name
if not name in self.users:
try:
uuid = self.astakos.service_get_uuid(self.astakos_token, name)
except NoUUID:
self.logger.debug("Failed to fetch uuid for %s", name)
except AstakosClientException:
pass
except Exception as err:
self.logger.error("Unexpected error while fetching " "user uuid %s: %s" % (name, repr(err)))
finally:
self.users[name] = uuid
return self.users[name]
def get_name(self, uuid):
name = "-"
if not uuid in self.users:
try:
name = self.astakos.service_get_username(self.astakos_token, uuid)
except NoUserName:
self.logger.debug("Failed to fetch display name for %s", uuid)
except AstakosClientException:
pass
except Exception as err:
self.logger.error("Unexpected error while fetching " "user displayname %s: %s" % (uuid, repr(err)))
finally:
self.users[uuid] = name
return self.users[uuid]