• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python identity.IdentityManager类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中mycroft.identity.IdentityManager的典型用法代码示例。如果您正苦于以下问题:Python IdentityManager类的具体用法?Python IdentityManager怎么用?Python IdentityManager使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



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

示例1: refresh_token

    def refresh_token(self):
        LOG.debug('Refreshing token')
        if identity_lock.acquire(blocking=False):
            try:
                data = self.send({
                    "path": "auth/token",
                    "headers": {
                        "Authorization": "Bearer " + self.identity.refresh
                    }
                })
                IdentityManager.save(data, lock=False)
                LOG.debug('Saved credentials')
            except HTTPError as e:
                if e.response.status_code == 401:
                    LOG.error('Could not refresh token, invalid refresh code.')
                else:
                    raise

            finally:
                identity_lock.release()
        else:  # Someone is updating the identity wait for release
            with identity_lock:
                LOG.debug('Refresh is already in progress, waiting until done')
                time.sleep(1.2)
                os.sync()
                self.identity = IdentityManager.load(lock=False)
                LOG.debug('new credentials loaded')
开发者ID:MycroftAI,项目名称:mycroft-core,代码行数:27,代码来源:__init__.py


示例2: refresh_token

 def refresh_token(self):
     data = self.send({
         "path": "auth/token",
         "headers": {
             "Authorization": "Bearer " + self.identity.refresh
         }
     })
     IdentityManager.save(data)
开发者ID:ChristopherRogers1991,项目名称:mycroft-core,代码行数:8,代码来源:__init__.py


示例3: check_token

 def check_token(self):
     # If the identity hasn't been loaded, load it
     if not self.identity.has_refresh():
         self.identity = IdentityManager.load()
     # If refresh is needed perform a refresh
     if self.identity.refresh and self.identity.is_expired():
         self.identity = IdentityManager.load()
         # if no one else has updated the token refresh it
         if self.identity.is_expired():
             self.refresh_token()
开发者ID:seymour-bootay,项目名称:mycroft-core,代码行数:10,代码来源:__init__.py


示例4: __init__

 def __init__(self, path):
     self.path = path
     config = ConfigurationManager().get()
     config_server = config.get("server")
     self.url = config_server.get("url")
     self.version = config_server.get("version")
     self.identity = IdentityManager.get()
开发者ID:ChristopherRogers1991,项目名称:mycroft-core,代码行数:7,代码来源:__init__.py


示例5: __init__

 def __init__(self, config=_config, pairing_code=None):
     self.config = config
     self.ws_client = WebsocketClient(host=config.get("host"),
                                      port=config.get("port"),
                                      path=config.get("route"),
                                      ssl=str2bool(config.get("ssl")))
     self.identity_manager = IdentityManager()
     self.identity = self.identity_manager.identity
     self.pairing_code = pairing_code if pairing_code else generate_pairing_code()
开发者ID:BK-University,项目名称:mycroft-core,代码行数:9,代码来源:client.py


示例6: has_been_paired

def has_been_paired():
    """ Determine if this device has ever been paired with a web backend

    Returns:
        bool: True if ever paired with backend (not factory reset)
    """
    # This forces a load from the identity file in case the pairing state
    # has recently changed
    id = IdentityManager.load()
    return id.uuid is not None and id.uuid != ""
开发者ID:seymour-bootay,项目名称:mycroft-core,代码行数:10,代码来源:__init__.py


示例7: DevicePairingClient

class DevicePairingClient(object):
    def __init__(self, config=_config, pairing_code=None):
        self.config = config
        self.paired = False
        self.ws_client = WebsocketClient(host=config.get("host"),
                                         port=config.get("port"),
                                         path=config.get("route"),
                                         ssl=str2bool(config.get("ssl")))
        self.identity_manager = IdentityManager()
        self.identity = self.identity_manager.identity
        self.pairing_code = (
            pairing_code if pairing_code else generate_pairing_code())

    def on_registration(self, message):
        # TODO: actually accept the configuration message and store it in
        # identity
        identity = self.identity_manager.get()
        register_payload = message.metadata
        if register_payload.get("device_id") == identity.device_id:
            identity.token = register_payload.get('token')
            identity.owner = register_payload.get('user')
            self.identity_manager.update(identity)
            self.ws_client.close()
            self.paired = True

    def send_device_info(self):
        msg = Message("device_info",
                      metadata={
                          "pairing_code": self.pairing_code,
                          "device_id": self.identity.device_id
                      })

        self.ws_client.emit(msg)

    @staticmethod
    def print_error(message):
        print(repr(message))

    def run(self):
        self.ws_client.on('registration', self.on_registration)
        self.ws_client.on('open', self.send_device_info)
        self.ws_client.on('error', self.print_error)
        self.ws_client.run_forever()
开发者ID:UberPanda,项目名称:mycroft-core,代码行数:43,代码来源:client.py


示例8: __init__

 def __init__(self, path):
     self.path = path
     config = Configuration.get([LocalConf(DEFAULT_CONFIG),
                                 LocalConf(SYSTEM_CONFIG),
                                 LocalConf(USER_CONFIG)],
                                cache=False)
     config_server = config.get("server")
     self.url = config_server.get("url")
     self.version = config_server.get("version")
     self.identity = IdentityManager.get()
开发者ID:antlarr,项目名称:mycroft-core,代码行数:10,代码来源:__init__.py


示例9: refresh_token

 def refresh_token(self):
     LOG.debug('Refreshing token')
     if identity_lock.acquire(blocking=False):
         try:
             data = self.send({
                 "path": "auth/token",
                 "headers": {
                     "Authorization": "Bearer " + self.identity.refresh
                 }
             })
             IdentityManager.save(data, lock=False)
             LOG.debug('Saved credentials')
         finally:
             identity_lock.release()
     else:  # Someone is updating the identity wait for release
         with identity_lock:
             LOG.debug('Refresh is already in progress, waiting until done')
             time.sleep(1.2)
             os.sync()
             self.identity = IdentityManager.load(lock=False)
             LOG.debug('new credentials loaded')
开发者ID:seymour-bootay,项目名称:mycroft-core,代码行数:21,代码来源:__init__.py


示例10: __init__

    def __init__(self, path):
        self.path = path

        # Load the config, skipping the REMOTE_CONFIG since we are
        # getting the info needed to get to it!
        config = Configuration.get([DEFAULT_CONFIG,
                                    SYSTEM_CONFIG,
                                    USER_CONFIG],
                                   cache=False)
        config_server = config.get("server")
        self.url = config_server.get("url")
        self.version = config_server.get("version")
        self.identity = IdentityManager.get()
开发者ID:seymour-bootay,项目名称:mycroft-core,代码行数:13,代码来源:__init__.py


示例11: handle_paired

def handle_paired(event):
    IdentityManager.update(event.data)
开发者ID:forslund,项目名称:mycroft-core,代码行数:2,代码来源:main.py


示例12: get_code

 def get_code(self, state):
     IdentityManager.update()
     return self.request({
         "path": "/code?state=" + state
     })
开发者ID:seymour-bootay,项目名称:mycroft-core,代码行数:5,代码来源:__init__.py


示例13: check_token

 def check_token(self):
     if self.identity.refresh and self.identity.is_expired():
         self.identity = IdentityManager.load()
         if self.identity.is_expired():
             self.refresh_token()
开发者ID:ChristopherRogers1991,项目名称:mycroft-core,代码行数:5,代码来源:__init__.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python ws.WebsocketClient类代码示例发布时间:2022-05-27
下一篇:
Python configuration.ConfigurationManager类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap