当前位置: 首页>>代码示例>>Python>>正文


Python AstakosClient.service_get_username方法代码示例

本文整理汇总了Python中astakosclient.AstakosClient.service_get_username方法的典型用法代码示例。如果您正苦于以下问题:Python AstakosClient.service_get_username方法的具体用法?Python AstakosClient.service_get_username怎么用?Python AstakosClient.service_get_username使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在astakosclient.AstakosClient的用法示例。


在下文中一共展示了AstakosClient.service_get_username方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: UserCache

# 需要导入模块: from astakosclient import AstakosClient [as 别名]
# 或者: from astakosclient.AstakosClient import service_get_username [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]
开发者ID:vkoukis,项目名称:synnefo,代码行数:73,代码来源:astakos.py


注:本文中的astakosclient.AstakosClient.service_get_username方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。