本文整理汇总了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')
示例2: refresh_token
def refresh_token(self):
data = self.send({
"path": "auth/token",
"headers": {
"Authorization": "Bearer " + self.identity.refresh
}
})
IdentityManager.save(data)
示例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()
示例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()
示例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()
示例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 != ""
示例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()
示例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()
示例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')
示例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()
示例11: handle_paired
def handle_paired(event):
IdentityManager.update(event.data)
示例12: get_code
def get_code(self, state):
IdentityManager.update()
return self.request({
"path": "/code?state=" + state
})
示例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()