本文整理汇总了Python中gi.repository.GnomeKeyring.lock_sync方法的典型用法代码示例。如果您正苦于以下问题:Python GnomeKeyring.lock_sync方法的具体用法?Python GnomeKeyring.lock_sync怎么用?Python GnomeKeyring.lock_sync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类gi.repository.GnomeKeyring
的用法示例。
在下文中一共展示了GnomeKeyring.lock_sync方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_create_lock
# 需要导入模块: from gi.repository import GnomeKeyring [as 别名]
# 或者: from gi.repository.GnomeKeyring import lock_sync [as 别名]
def test_create_lock(self):
'''create_sync() and locking/unlocking'''
# create
self.assertEqual(GnomeKeyring.create_sync(TEST_KEYRING, TEST_PWD),
GnomeKeyring.Result.OK)
(result, info) = GnomeKeyring.get_info_sync(TEST_KEYRING)
self.assertEqual(result, GnomeKeyring.Result.OK)
self.assertFalse(info.get_is_locked())
# try to create already existing ring
self.assertEqual(GnomeKeyring.create_sync(TEST_KEYRING, TEST_PWD),
GnomeKeyring.Result.KEYRING_ALREADY_EXISTS)
# lock
self.assertEqual(GnomeKeyring.lock_sync(TEST_KEYRING),
GnomeKeyring.Result.OK)
self.assertTrue(GnomeKeyring.get_info_sync(TEST_KEYRING)[1].get_is_locked())
# unlock with wrong password
self.assertEqual(GnomeKeyring.unlock_sync(TEST_KEYRING, 'h4ck'),
GnomeKeyring.Result.IO_ERROR)
# unlock with correct password
self.assertEqual(GnomeKeyring.unlock_sync(TEST_KEYRING, TEST_PWD),
GnomeKeyring.Result.OK)
示例2: lock
# 需要导入模块: from gi.repository import GnomeKeyring [as 别名]
# 或者: from gi.repository.GnomeKeyring import lock_sync [as 别名]
def lock(self):
result = GnomeKeyring.lock_sync(self.keyring)
if result == GnomeKeyring.Result.OK:
return True
return False
示例3: compile
# 需要导入模块: from gi.repository import GnomeKeyring [as 别名]
# 或者: from gi.repository.GnomeKeyring import lock_sync [as 别名]
import getpass
result = gkr.unlock_sync('login',
getpass.getpass(prompt='Enter password for '
'login keyring: '))
if result == gkr.Result.IO_ERROR: # Incorrect password
sys.exit(1)
# Connect to libsecret
service = Secret.Service.get_sync(Secret.ServiceFlags.OPEN_SESSION |
Secret.ServiceFlags.LOAD_COLLECTIONS)
collections = service.get_collections()
# Search the default keyring
items = service.unlock_sync(collections, None)[1][0].get_items()
# Match the item's name using the search string as a regular expression
found = [i for i in items if compile(sys.argv[1]).search(i.get_label())]
if len(found):
# Prompt the user to display any results. Use curses.wrapper to ensure
# things are taken care of in case of a KeyboardInterrupt or other
# exception, and that the screen is wiped afterwards.
curses.wrapper(display_results, found)
else:
# Helpful feedback
print("No matches for search term '{}'.".format(sys.argv[1]))
# Relock the keyring if necessary
if was_locked:
gkr.lock_sync(KEYRING)