本文整理汇总了Python中gi.repository.Secret类的典型用法代码示例。如果您正苦于以下问题:Python Secret类的具体用法?Python Secret怎么用?Python Secret使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Secret类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: connect
def connect(self, password):
"""
Connect lastfm
@param password as str/None
"""
if self._goa:
t = Thread(target=self._connect, args=('', '', True))
t.daemon = True
t.start()
# Get username/password from GSettings/Secret
elif Secret is not None and\
Gio.NetworkMonitor.get_default().get_network_available():
self._username = Lp().settings.get_value(
'lastfm-login').get_string()
if password is None:
schema = Secret.Schema.new("org.gnome.Lollypop",
Secret.SchemaFlags.NONE,
SecretSchema)
Secret.password_lookup(schema, SecretAttributes, None,
self._on_password_lookup)
else:
t = Thread(target=self._connect, args=(self._username,
password, True))
t.daemon = True
t.start()
示例2: set_account_password
def set_account_password(email, password):
attrs = {"email": email}
if password:
Secret.password_store_sync(_ACCOUNT_SCHEMA, attrs, Secret.COLLECTION_DEFAULT,
"Pandora Account", password, None)
else:
Secret.password_clear_sync(_ACCOUNT_SCHEMA, attrs, None)
示例3: insert
def insert(secret_id, provider, username, token):
"""
Save a secret OTP token.
:param secret_id: The secret ID associated to the OTP token
:param provider: the provider name
:param username: the username
:param token: the secret OTP token.
"""
schema = Keyring.get_default().schema
data = {
"id": str(secret_id),
"name": str(username),
}
Secret.password_store_sync(
schema,
data,
Secret.COLLECTION_DEFAULT,
"{provider} OTP ({username})".format(
provider=provider, username=username),
token,
None
)
示例4: _update_lastfm_settings
def _update_lastfm_settings(self, sync=False):
"""
Update lastfm settings
@param sync as bool
"""
try:
if Lp().lastfm is not None and Secret is not None:
schema = Secret.Schema.new("org.gnome.Lollypop",
Secret.SchemaFlags.NONE,
SecretSchema)
Secret.password_store_sync(schema, SecretAttributes,
Secret.COLLECTION_DEFAULT,
"org.gnome.Lollypop"
".lastfm.login %s" %
self.__login.get_text(),
self.__password.get_text(),
None)
Lp().settings.set_value('lastfm-login',
GLib.Variant('s',
self.__login.get_text()))
if sync:
Lp().lastfm.connect_sync(self.__password.get_text())
else:
Lp().lastfm.connect(self.__password.get_text())
except Exception as e:
print("Settings::_update_lastfm_settings(): %s" % e)
示例5: testSynchronous
def testSynchronous(self):
attributes = { "number": "1", "string": "one", "even": "false" }
password = Secret.password_lookup_sync(STORE_SCHEMA, attributes, None)
self.assertEqual("111", password)
deleted = Secret.password_remove_sync(STORE_SCHEMA, attributes, None)
self.assertEqual(True, deleted)
示例6: testSyncNotFound
def testSyncNotFound(self):
attributes = { "number": "11", "string": "one", "even": "true" }
password = Secret.password_lookup_sync(STORE_SCHEMA, attributes, None)
self.assertEqual(None, password)
deleted = Secret.password_remove_sync(STORE_SCHEMA, attributes, None)
self.assertEqual(False, deleted)
示例7: store_password
def store_password(self, scheme, host, username, password):
"""Return the password of [email protected]"""
template = dict(zip(self.category, (scheme, host, username)))
self.clear_password(scheme, host, username)
try:
Secret.password_store_sync(
self.schema, template, Secret.COLLECTION_DEFAULT, host,
password, None)
except Secret.SECRET_ERROR_PROTOCOL:
pass
示例8: erase
def erase():
attributes = get_attributes()
if 'password' in attributes:
del attributes['password']
Secret.password_clear_sync(
GIT_CREDENTIALS_SCHEMA,
attributes,
None
)
示例9: setTokens
def setTokens(self, user, access_token, refresh_token):
attributes = {
"user": user,
"scope": self.scope,
}
Secret.password_store_sync(self.TOKEN_SCHEMA, attributes,
Secret.COLLECTION_DEFAULT,
"Mail access to %s for %s" % (self.scope, user),
self.encodeTokens(access_token, refresh_token),
None
)
示例10: set_account_password
def set_account_password(self, old_email, new_email, password, callback):
def on_password_store_finish(source, result, data):
try:
success = Secret.password_store_finish(result)
except GLib.Error as e:
logging.error('Failed to store password, Error: {}'.format(e))
success = False
if callback:
callback(success)
def on_password_clear_finish(source, result, data):
try:
password_removed = Secret.password_clear_finish(result)
if password_removed:
logging.debug('Cleared password for: {}'.format(old_email))
else:
logging.debug('No password found to clear for: {}'.format(old_email))
except GLib.Error as e:
logging.error('Failed to clear password for: {}, Error: {}'.format(old_email, e))
if callback:
callback(False)
else:
Secret.password_store(
self._account_schema,
{'email': new_email},
self._current_collection,
'Pandora Account',
password,
None,
on_password_store_finish,
None,
)
if old_email and old_email != new_email:
Secret.password_clear(
self._account_schema,
{'email': old_email},
None,
on_password_clear_finish,
None,
)
else:
Secret.password_store(
self._account_schema,
{'email': new_email},
self._current_collection,
'Pandora Account',
password,
None,
on_password_store_finish,
None,
)
示例11: testValueGet
def testValueGet(self):
Secret.password_store_sync(EXAMPLE_SCHEMA, attributes, Secret.COLLECTION_DEFAULT,
'the label', 'the password', None)
service = SecretUnstable.Service.get_sync(SecretUnstable.ServiceFlags.NONE, None)
items = service.search_sync(EXAMPLE_SCHEMA, { 'even': 'true' },
SecretUnstable.SearchFlags.ALL | SecretUnstable.SearchFlags.LOAD_SECRETS,
None)
item = items[0]
item_secret = item.get_secret()
self.assertEqual(item_secret.get(), "the password")
示例12: testAsynchronous
def testAsynchronous(self):
loop = GLib.MainLoop(None)
def on_result_ready(source, result, unused):
loop.quit()
password = Secret.password_lookup_finish(result)
self.assertEquals("222", password)
Secret.password_lookup (STORE_SCHEMA, { "number": "2", "string": "two" },
None, on_result_ready, None)
loop.run()
示例13: testAsyncNotFound
def testAsyncNotFound(self):
loop = GLib.MainLoop(None, False)
def on_result_ready(source, result, unused):
loop.quit()
password = Secret.password_lookup_finish(result)
self.assertEquals(None, password)
Secret.password_lookup (STORE_SCHEMA, { "number": "7", "string": "five" },
None, on_result_ready, None)
loop.run()
示例14: testAsynchronous
def testAsynchronous(self):
loop = GLib.MainLoop(None, False)
def on_result_ready(source, result, unused):
loop.quit()
deleted = Secret.password_remove_finish(result)
self.assertEquals(True, deleted)
Secret.password_remove(STORE_SCHEMA, { "number": "2", "string": "two" },
None, on_result_ready, None)
loop.run()
示例15: testSynchronous
def testSynchronous(self):
attributes = { "number": "9", "string": "nine", "even": "false" }
password = Secret.password_lookup_sync(STORE_SCHEMA, attributes, None)
self.assertEqual(None, password)
stored = Secret.password_store_sync(STORE_SCHEMA, attributes, Secret.COLLECTION_DEFAULT,
"The number nine", "999", None)
self.assertEqual(True, stored);
password = Secret.password_lookup_sync(STORE_SCHEMA, attributes, None)
self.assertEqual("999", password)