本文整理汇总了Python中gi.repository.GnomeKeyring.item_get_info_sync方法的典型用法代码示例。如果您正苦于以下问题:Python GnomeKeyring.item_get_info_sync方法的具体用法?Python GnomeKeyring.item_get_info_sync怎么用?Python GnomeKeyring.item_get_info_sync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类gi.repository.GnomeKeyring
的用法示例。
在下文中一共展示了GnomeKeyring.item_get_info_sync方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: set
# 需要导入模块: from gi.repository import GnomeKeyring [as 别名]
# 或者: from gi.repository.GnomeKeyring import item_get_info_sync [as 别名]
def set(self, protocol, user, server, password):
if password != '':
displayNameDict = {}
(result, ids) = GnomeKeyring.list_item_ids_sync(self._defaultKeyring)
for identity in ids:
(result, item) = GnomeKeyring.item_get_info_sync(self._defaultKeyring, identity)
displayNameDict[item.get_display_name()] = identity
attrs = GnomeKeyring.Attribute.list_new()
GnomeKeyring.Attribute.list_append_string(attrs, 'application', 'Mailnag')
GnomeKeyring.Attribute.list_append_string(attrs, 'protocol', protocol)
GnomeKeyring.Attribute.list_append_string(attrs, 'user', user)
GnomeKeyring.Attribute.list_append_string(attrs, 'server', server)
if self.KEYRING_ITEM_NAME % (protocol, user, server) in displayNameDict:
(result, item) = GnomeKeyring.item_get_info_sync(self._defaultKeyring, \
displayNameDict[self.KEYRING_ITEM_NAME % \
(protocol, user, server)])
if password != item.get_secret():
GnomeKeyring.item_create_sync(self._defaultKeyring, \
GnomeKeyring.ItemType.GENERIC_SECRET, \
self.KEYRING_ITEM_NAME % (protocol, user, server), \
attrs, password, True)
else:
GnomeKeyring.item_create_sync(self._defaultKeyring, \
GnomeKeyring.ItemType.GENERIC_SECRET, \
self.KEYRING_ITEM_NAME % (protocol, user, server), \
attrs, password, True)
示例2: find_keyring_items
# 需要导入模块: from gi.repository import GnomeKeyring [as 别名]
# 或者: from gi.repository.GnomeKeyring import item_get_info_sync [as 别名]
def find_keyring_items(self):
attrs = GnomeKeyring.Attribute.list_new()
GnomeKeyring.Attribute.list_append_string(attrs, 'rhythmbox-plugin', 'pandora')
result, items = GnomeKeyring.find_items_sync(GnomeKeyring.ItemType.GENERIC_SECRET, attrs)
if (result is None or result is GnomeKeyring.Result.OK) and len(items) != 0: # Got list of search results
self.__keyring_data['id'] = items[0].item_id
result, item = GnomeKeyring.item_get_info_sync(None, self.__keyring_data['id'])
if result is None or result is GnomeKeyring.Result.OK: # Item retrieved successfully
self.__keyring_data['item'] = item
self.fill_account_details()
else:
print("Couldn't retrieve keyring item: " + str(result))
elif result == GnomeKeyring.Result.NO_MATCH or len(items) == 0: # No items were found, so we'll create one
result, id = GnomeKeyring.item_create_sync(
None,
GnomeKeyring.ItemType.GENERIC_SECRET,
"Rhythmbox: Pandora account information",
attrs,
"", # Empty secret for now
True)
if result is None or result is GnomeKeyring.Result.OK: # Item successfully created
self.__keyring_data['id'] = id
result, item = GnomeKeyring.item_get_info_sync(None, id)
if result is None: # Item retrieved successfully
self.__keyring_data['item'] = item
self.fill_account_details()
else:
print("Couldn't retrieve keyring item: " + str(result))
else:
print("Couldn't create keyring item: " + str(result))
else: # Some other error occurred
print("Couldn't access keyring: " + str(result))
示例3: get
# 需要导入模块: from gi.repository import GnomeKeyring [as 别名]
# 或者: from gi.repository.GnomeKeyring import item_get_info_sync [as 别名]
def get(self, protocol, user, server):
(result, ids) = GnomeKeyring.list_item_ids_sync(self._defaultKeyring)
if result == GnomeKeyring.Result.OK:
displayNameDict = {}
for identity in ids:
(result, item) = GnomeKeyring.item_get_info_sync(self._defaultKeyring, identity)
displayNameDict[item.get_display_name()] = identity
if self.KEYRING_ITEM_NAME % (protocol, user, server) in displayNameDict:
(result, item) = GnomeKeyring.item_get_info_sync(self._defaultKeyring, \
displayNameDict[self.KEYRING_ITEM_NAME % \
(protocol, user, server)])
if item.get_secret() != '':
return item.get_secret()
else:
# DEBUG print "Keyring.get(): No Keyring Password for %s://%[email protected]%s." % (protocol, user, server)
return ''
else:
# DEBUG print "Keyring.get(): %s://%[email protected]%s not in Keyring." % (protocol, user, server)
return ''
else:
# DEBUG print "Keyring.get(): Neither default- nor 'login'-Keyring available."
return ''
示例4: get_password
# 需要导入模块: from gi.repository import GnomeKeyring [as 别名]
# 或者: from gi.repository.GnomeKeyring import item_get_info_sync [as 别名]
def get_password(self, item_id):
result, item_info = GnomeKeyring.item_get_info_sync(
self.keyring, item_id)
if result == GnomeKeyring.Result.OK:
return item_info.get_secret()
else:
return ""
示例5: test_item_create_info
# 需要导入模块: from gi.repository import GnomeKeyring [as 别名]
# 或者: from gi.repository.GnomeKeyring import item_get_info_sync [as 别名]
def test_item_create_info(self):
'''item_create_sync(), item_get_info_sync(), list_item_ids_sync()'''
self.assertEqual(GnomeKeyring.create_sync(TEST_KEYRING, TEST_PWD),
GnomeKeyring.Result.OK)
self.assertEqual(GnomeKeyring.get_info_sync(TEST_KEYRING)[0], GnomeKeyring.Result.OK)
attrs = GnomeKeyring.Attribute.list_new()
GnomeKeyring.Attribute.list_append_string(attrs, 'context', 'testsuite')
GnomeKeyring.Attribute.list_append_uint32(attrs, 'answer', 42)
(result, id) = GnomeKeyring.item_create_sync(TEST_KEYRING,
GnomeKeyring.ItemType.GENERIC_SECRET, 'my_password', attrs,
'my_secret', False)
self.assertEqual(result, GnomeKeyring.Result.OK)
# now query for it
(result, info) = GnomeKeyring.item_get_info_sync(TEST_KEYRING, id)
self.assertEqual(result, GnomeKeyring.Result.OK)
self.assertEqual(info.get_display_name(), 'my_password')
self.assertEqual(info.get_secret(), 'my_secret')
# list_item_ids_sync()
(result, items) = GnomeKeyring.list_item_ids_sync(TEST_KEYRING)
self.assertEqual(result, GnomeKeyring.Result.OK)
self.assertEqual(items, [id])
示例6: get_master_key
# 需要导入模块: from gi.repository import GnomeKeyring [as 别名]
# 或者: from gi.repository.GnomeKeyring import item_get_info_sync [as 别名]
def get_master_key():
ids = GnomeKeyring.list_item_ids_sync(KEYRING)[1]
for id in ids:
info = GnomeKeyring.item_get_info_sync('login', id)[1]
if info.get_display_name() == 'gpwg:masterkey':
return info.get_secret()
return None
示例7: _get_first_key
# 需要导入模块: from gi.repository import GnomeKeyring [as 别名]
# 或者: from gi.repository.GnomeKeyring import item_get_info_sync [as 别名]
def _get_first_key(self, keyring):
item_keys = gk.list_item_ids_sync(keyring)
if len(item_keys[1]) > 0:
item_info = gk.item_get_info_sync(keyring, item_keys[1][0])
return (item_info[1].get_display_name(), item_info[1].get_secret())
else:
return False
示例8: _find
# 需要导入模块: from gi.repository import GnomeKeyring [as 别名]
# 或者: from gi.repository.GnomeKeyring import item_get_info_sync [as 别名]
def _find(self, displayName, keyring):
item_keys = gk.list_item_ids_sync(keyring)
for k in item_keys[1]:
item_info = gk.item_get_info_sync(keyring, k)
if item_info.get_display_name() == displayName:
return (k, item_info.get_display_name(), item_info.get_secret())
return False
示例9: remove_by_id
# 需要导入模块: from gi.repository import GnomeKeyring [as 别名]
# 或者: from gi.repository.GnomeKeyring import item_get_info_sync [as 别名]
def remove_by_id(self, uid):
"""
Remove an account by uid
:param uid: (int) account uid
:return:
"""
secret_code = self.get_secret_code(uid)
if secret_code:
found = False
(result, ids) = GK.list_item_ids_sync("TwoFactorAuth")
for gid in ids:
(result, item) = GK.item_get_info_sync("TwoFactorAuth", gid)
if result == GK.Result.OK:
if item.get_display_name().strip("'") == secret_code:
found = True
break
if found:
GK.item_delete_sync("TwoFactorAuth", gid)
query = "DELETE FROM accounts WHERE uid=?"
try:
self.conn.execute(query, (uid,))
self.conn.commit()
except Exception as e:
logging.error(
"SQL: Couldn't remove account by uid : %s with error : %s" % (uid, str(e)))
示例10: _get_keyring_item_info
# 需要导入模块: from gi.repository import GnomeKeyring [as 别名]
# 或者: from gi.repository.GnomeKeyring import item_get_info_sync [as 别名]
def _get_keyring_item_info(self, item_id):
result, value = GnomeKeyring.item_get_info_sync(
GnomeCredentialStore.KEYRING_NAME,
item_id)
if result != GnomeKeyring.Result.OK:
logger.debug("Failed to get keyring info for item_id %s: %s" % (item_id, result))
return None
logger.debug("Successfully got keyring item info for item_id %s" % item_id)
return value
示例11: _migrate_keyring
# 需要导入模块: from gi.repository import GnomeKeyring [as 别名]
# 或者: from gi.repository.GnomeKeyring import item_get_info_sync [as 别名]
def _migrate_keyring(self):
attrs = GnomeKeyring.Attribute.list_new()
GnomeKeyring.Attribute.list_append_string(attrs, 'application', 'Mailnag')
result, items = GnomeKeyring.find_items_sync(GnomeKeyring.ItemType.GENERIC_SECRET, attrs)
if result == GnomeKeyring.Result.OK:
for i in items:
result, info = GnomeKeyring.item_get_info_sync(self._defaultKeyring, i.item_id)
self.set(info.get_display_name(), i.secret)
GnomeKeyring.item_delete_sync(self._defaultKeyring, i.item_id)
示例12: __init__
# 需要导入模块: from gi.repository import GnomeKeyring [as 别名]
# 或者: from gi.repository.GnomeKeyring import item_get_info_sync [as 别名]
def __init__(self):
self.keyring_item = None
self.keyring_attributes = GnomeKeyring.attribute_list_new()
GnomeKeyring.attribute_list_append_string(self.keyring_attributes,
"rhythmbox-plugin",
"vkontakte")
(result, items) = GnomeKeyring.find_items_sync(GnomeKeyring.ItemType.GENERIC_SECRET,
self.keyring_attributes)
if result == GnomeKeyring.Result.OK and len(items) != 0:
(result, item) = GnomeKeyring.item_get_info_sync(None, items[0].item_id)
if result == GnomeKeyring.Result.OK:
self.keyring_item = item
else:
print "Couldn't get keyring item: " + GnomeKeyring.result_to_message(result)
else:
print "couldn't search keyring items: " + GnomeKeyring.result_to_message(result)
示例13: remove
# 需要导入模块: from gi.repository import GnomeKeyring [as 别名]
# 或者: from gi.repository.GnomeKeyring import item_get_info_sync [as 别名]
def remove(self, accounts):
# create list of all valid accounts
valid_accounts = []
for acc in accounts:
protocol = 'imap' if acc.imap else 'pop'
valid_accounts.append(self.KEYRING_ITEM_NAME % \
(protocol, acc.user, acc.server))
# find and delete invalid entries
(result, ids) = GnomeKeyring.list_item_ids_sync(self._defaultKeyring)
if result == GnomeKeyring.Result.OK:
displayNameDict = {}
for identity in ids:
(result, item) = GnomeKeyring.item_get_info_sync(self._defaultKeyring, identity)
displayNameDict[item.get_display_name()] = identity
for key in displayNameDict.keys():
if key.startswith('Mailnag password for') \
and key not in valid_accounts:
GnomeKeyring.item_delete_sync(self._defaultKeyring, displayNameDict[key])
示例14: dump
# 需要导入模块: from gi.repository import GnomeKeyring [as 别名]
# 或者: from gi.repository.GnomeKeyring import item_get_info_sync [as 别名]
def dump(self, print_passwords=False):
"""Get all keyring entries (with or without passwords)
"""
from gi.repository import GnomeKeyring
dump = ""
(result, ids) = GnomeKeyring.list_item_ids_sync(self.KEYRING_NAME)
for id in ids:
(result, item) = GnomeKeyring.item_get_info_sync(self.KEYRING_NAME, id)
if result == GnomeKeyring.Result.IO_ERROR:
return None
if result == GnomeKeyring.Result.NO_MATCH:
return None
if result == GnomeKeyring.Result.CANCELLED:
# The user pressed "Cancel" when prompted to unlock their keyring.
return None
dump += item.get_display_name()
if print_passwords:
dump += " = " + item.get_secret()
dump += "\n"
return dump
示例15: update
# 需要导入模块: from gi.repository import GnomeKeyring [as 别名]
# 或者: from gi.repository.GnomeKeyring import item_get_info_sync [as 别名]
def update(self, username, password):
secret = '\n'.join((username, password))
if self.keyring_item is not None:
if secret == self.keyring_item.get_secret():
print "account details not changed"
return
(result, id) = GnomeKeyring.item_create_sync(None,
GnomeKeyring.ItemType.GENERIC_SECRET,
"Rhythmbox: Vkontakte account information",
self.keyring_attributes,
secret,
True)
if result == GnomeKeyring.Result.OK:
if self.keyring_item is None:
(result, item) = GnomeKeyring.item_get_info_sync(None, id)
if result == GnomeKeyring.Result.OK:
self.keyring_item = item
else:
print "couldn't fetch keyring item: " + GnomeKeyring.result_to_message(result)
else:
print "couldn't create keyring item: " + GnomeKeyring.result_to_message(result)