本文整理汇总了Python中gi.repository.GnomeKeyring.find_items_sync方法的典型用法代码示例。如果您正苦于以下问题:Python GnomeKeyring.find_items_sync方法的具体用法?Python GnomeKeyring.find_items_sync怎么用?Python GnomeKeyring.find_items_sync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类gi.repository.GnomeKeyring
的用法示例。
在下文中一共展示了GnomeKeyring.find_items_sync方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_find_items
# 需要导入模块: from gi.repository import GnomeKeyring [as 别名]
# 或者: from gi.repository.GnomeKeyring import find_items_sync [as 别名]
def test_find_items(self):
'''find_items_sync()'''
search_attrs = GnomeKeyring.Attribute.list_new()
# no attributes, finds everything
(result, items) = GnomeKeyring.find_items_sync(
GnomeKeyring.ItemType.GENERIC_SECRET,
search_attrs)
self.assertEqual(result, GnomeKeyring.Result.OK)
print('(no attributes: %i matches) ' % len(items), end='', file=sys.stderr)
for item in items:
self.assertNotEqual(item.keyring, '')
for attr in GnomeKeyring.Attribute.list_to_glist(item.attributes):
self.assertTrue(attr.type in (GnomeKeyring.AttributeType.STRING,
GnomeKeyring.AttributeType.UINT32))
self.assertEqual(type(attr.name), type(''))
self.assertGreater(len(attr.name), 0)
# check that we can get the value
if attr.type == GnomeKeyring.AttributeType.STRING:
self.assertEqual(type(attr.get_string()), type(''))
else:
self.assertTrue(isinstance(attr.get_uint32()), long)
# search for unknown attribute, should have no results
GnomeKeyring.Attribute.list_append_string(search_attrs, 'unknown!_attr', '')
(result, items) = GnomeKeyring.find_items_sync(
GnomeKeyring.ItemType.GENERIC_SECRET,
search_attrs)
self.assertEqual(result, GnomeKeyring.Result.NO_MATCH)
self.assertEqual(len(items), 0)
示例2: find_keyring_items
# 需要导入模块: from gi.repository import GnomeKeyring [as 别名]
# 或者: from gi.repository.GnomeKeyring import find_items_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 find_items_sync [as 别名]
def get(self, key):
attrs = self._get_attrs(key)
result, items = GnomeKeyring.find_items_sync(GnomeKeyring.ItemType.GENERIC_SECRET, attrs)
if result == GnomeKeyring.Result.OK:
return items[0].secret
else:
return ''
示例4: fetch_secret_code
# 需要导入模块: from gi.repository import GnomeKeyring [as 别名]
# 或者: from gi.repository.GnomeKeyring import find_items_sync [as 别名]
def fetch_secret_code(secret_code):
attr = GK.Attribute.list_new()
GK.Attribute.list_append_string(attr, 'id', secret_code)
result, value = GK.find_items_sync(GK.ItemType.GENERIC_SECRET, attr)
if result == GK.Result.OK:
return value[0].secret
else:
return None
示例5: find_folder
# 需要导入模块: from gi.repository import GnomeKeyring [as 别名]
# 或者: from gi.repository.GnomeKeyring import find_items_sync [as 别名]
def find_folder(self,epath):
attributes = GnomeKeyring.Attribute.list_new()
GnomeKeyring.Attribute.list_append_string(attributes, 'appid', APPID)
GnomeKeyring.Attribute.list_append_string(attributes, 'encfs-path', epath)
ff = GnomeKeyring.find_items_sync(GnomeKeyring.ItemType.GENERIC_SECRET, attributes)[1]
if len(ff)>0:
return ff[0].item_id, ff[0].secret
else:
return None
示例6: delete_credentials
# 需要导入模块: from gi.repository import GnomeKeyring [as 别名]
# 或者: from gi.repository.GnomeKeyring import find_items_sync [as 别名]
def delete_credentials(self, user):
attrs = attributes({
"user": user,
"server": self._server,
"protocol": self._protocol
})
result, items = GnomeKeyring.find_items_sync(GnomeKeyring.ItemType.NETWORK_PASSWORD, attrs)
for item in items:
GnomeKeyring.item_delete_sync(self._keyring, item.item_id)
示例7: _migrate_keyring
# 需要导入模块: from gi.repository import GnomeKeyring [as 别名]
# 或者: from gi.repository.GnomeKeyring import find_items_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)
示例8: get_all_users
# 需要导入模块: from gi.repository import GnomeKeyring [as 别名]
# 或者: from gi.repository.GnomeKeyring import find_items_sync [as 别名]
def get_all_users(self):
attrs = attributes({"server": self._server, "protocol": self._protocol})
result, items = GnomeKeyring.find_items_sync(GnomeKeyring.ItemType.NETWORK_PASSWORD, attrs)
if len(items) == 0:
raise KeyringException("Credentials not found")
users_list = []
for item in items:
d = dict_from_attributes(item.attributes)
users_list.append(d["user"])
return users_list
示例9: get_credentials
# 需要导入模块: from gi.repository import GnomeKeyring [as 别名]
# 或者: from gi.repository.GnomeKeyring import find_items_sync [as 别名]
def get_credentials(self, user):
attrs = attributes({
"user" : user,
"server": self._server,
"protocol": self._protocol
})
result, items = GnomeKeyring.find_items_sync(GnomeKeyring.ItemType.NETWORK_PASSWORD, attrs)
if len(items) == 0:
raise KeyringException("Credentials not found")
d = dict_from_attributes(items[0].attributes)
return Credentials(d["user"], items[0].secret)
示例10: get_from_keyring
# 需要导入模块: from gi.repository import GnomeKeyring [as 别名]
# 或者: from gi.repository.GnomeKeyring import find_items_sync [as 别名]
def get_from_keyring(acctid, name):
"""Get the entry from the keyring for @acctid with @name."""
attributes = GnomeKeyring.Attribute.list_new()
GnomeKeyring.Attribute.list_append_string(attributes, 'id',
str("%s/%s" % (acctid, name)))
result, value = GnomeKeyring.find_items_sync(
GnomeKeyring.ItemType.GENERIC_SECRET,
attributes)
if result == GnomeKeyring.Result.OK:
return value[0].secret
return None
示例11: _get_value_from_gnomekeyring
# 需要导入模块: from gi.repository import GnomeKeyring [as 别名]
# 或者: from gi.repository.GnomeKeyring import find_items_sync [as 别名]
def _get_value_from_gnomekeyring(self, name):
"""Get a locked secret for threaded/multiprocessing use."""
value = ""
attrlist = GnomeKeyring.Attribute.list_new()
GnomeKeyring.Attribute.list_append_string(attrlist, "id", str(name))
result, found = GnomeKeyring.find_items_sync(GnomeKeyring.ItemType.GENERIC_SECRET, attrlist)
if result == GnomeKeyring.Result.OK:
value = found[0].secret
mlock(value)
return value
elif result == GnomeKeyring.Result.NO_MATCH:
raise (NoPasswordFound())
raise (GnomeKeyringLocked())
示例12: do_query
# 需要导入模块: from gi.repository import GnomeKeyring [as 别名]
# 或者: from gi.repository.GnomeKeyring import find_items_sync [as 别名]
def do_query(self, id):
# Fetch secret by id
attrs = GnomeKeyring.Attribute.list_new()
GnomeKeyring.Attribute.list_append_string(attrs, 'id', id)
result, value = GnomeKeyring.find_items_sync(GnomeKeyring.ItemType.GENERIC_SECRET, attrs)
if result != GnomeKeyring.Result.OK:
return
#print 'password %s = %s' % (id, value[0].secret)
#print 'password id = %s' % value[0].item_id
username, password = value[0].secret.split('@@@')
Liferea.auth_info_from_store(id, username, password)
示例13: gkr_get
# 需要导入模块: from gi.repository import GnomeKeyring [as 别名]
# 或者: from gi.repository.GnomeKeyring import find_items_sync [as 别名]
def gkr_get(self, id):
attrs = GnomeKeyring.Attribute.list_new()
GnomeKeyring.Attribute.list_append_string(attrs, 'id', id)
result, value = GnomeKeyring.find_items_sync(GnomeKeyring.ItemType.GENERIC_SECRET, attrs)
if result == GnomeKeyring.Result.OK:
return value[0].secret
elif result == GnomeKeyring.Result.NO_MATCH:
# Key doesn't exist, create again
print(_("Key doesn't exist in GNOME Keyring. Creating again..."))
self.gkr_store(GUIFINETLOGINKEYNAME, ':')
return ''
else:
return None
示例14: get_keyring_password
# 需要导入模块: from gi.repository import GnomeKeyring [as 别名]
# 或者: from gi.repository.GnomeKeyring import find_items_sync [as 别名]
def get_keyring_password():
GnomeKeyring.unlock_sync("login", None)
attrs = GnomeKeyring.Attribute.list_new()
GnomeKeyring.Attribute.list_append_string(attrs, "id", "resnet")
result, value = GnomeKeyring.find_items_sync(GnomeKeyring.ItemType.GENERIC_SECRET, attrs)
if result == GnomeKeyring.Result.OK:
return value[0].secret
elif result == GnomeKeyring.Result.NO_MATCH:
# Password not found, prompt to add new one
print("Password not found in keyring")
password = getpass.getpass("OSU Login Password: ")
GnomeKeyring.item_create_sync("login", GnomeKeyring.ItemType.GENERIC_SECRET, "resnet", attrs, password, True)
return password
elif result != GnomeKeyring.Result.OK:
return None
示例15: get_secret
# 需要导入模块: from gi.repository import GnomeKeyring [as 别名]
# 或者: from gi.repository.GnomeKeyring import find_items_sync [as 别名]
def get_secret(id):
"""Get a locked secret for threaded/multiprocessing use."""
value = ""
attrlist = GnomeKeyring.Attribute.list_new()
GnomeKeyring.Attribute.list_append_string(attrlist, 'id', str(id))
result, found = GnomeKeyring.find_items_sync(
GnomeKeyring.ItemType.GENERIC_SECRET,
attrlist)
if result == GnomeKeyring.Result.OK:
value = found[0].secret
mlock(value)
return value
elif result == GnomeKeyring.Result.NO_MATCH:
print "FAILED: " + id
return None