当前位置: 首页>>代码示例>>Python>>正文


Python GnomeKeyring.get_info_sync方法代码示例

本文整理汇总了Python中gi.repository.GnomeKeyring.get_info_sync方法的典型用法代码示例。如果您正苦于以下问题:Python GnomeKeyring.get_info_sync方法的具体用法?Python GnomeKeyring.get_info_sync怎么用?Python GnomeKeyring.get_info_sync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在gi.repository.GnomeKeyring的用法示例。


在下文中一共展示了GnomeKeyring.get_info_sync方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_create_lock

# 需要导入模块: from gi.repository import GnomeKeyring [as 别名]
# 或者: from gi.repository.GnomeKeyring import get_info_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)
开发者ID:Bchelz,项目名称:libgnome-keyring,代码行数:28,代码来源:test-gi.py

示例2: test_item_create_info

# 需要导入模块: from gi.repository import GnomeKeyring [as 别名]
# 或者: from gi.repository.GnomeKeyring import 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])
开发者ID:Bchelz,项目名称:libgnome-keyring,代码行数:28,代码来源:test-gi.py

示例3: test_info_default

# 需要导入模块: from gi.repository import GnomeKeyring [as 别名]
# 或者: from gi.repository.GnomeKeyring import get_info_sync [as 别名]
    def test_info_default(self):
        '''get_info_sync() for default keyring'''

        # we cannot assume too much about the default keyring; it might be
        # locked or not, and we should avoid poking in it too much
        (result, info) = GnomeKeyring.get_info_sync(None)
        self.assertEqual(result, GnomeKeyring.Result.OK)
        self.assertTrue(info.get_is_locked() in (False, True))
开发者ID:Bchelz,项目名称:libgnome-keyring,代码行数:10,代码来源:test-gi.py

示例4: setup_gnome_keyring

# 需要导入模块: from gi.repository import GnomeKeyring [as 别名]
# 或者: from gi.repository.GnomeKeyring import get_info_sync [as 别名]
def setup_gnome_keyring():
    """
    Provide clean login Gnome keyring (removes the previous one
    beforehand, if there is a one).
    """
    try:
        # Delete originally stored password
        (response, keyring) = GnomeKeyring.get_default_keyring_sync()
        log.debug('get_info default: %s, %s' % (response, keyring))
        if response == GnomeKeyring.Result.OK:
            if keyring is not None:
                delete_response = GnomeKeyring.delete_sync(keyring)
                log.debug('delete default: %s' % delete_response)
                assert delete_response == GnomeKeyring.Result.OK, \
                    "Delete failed: %s" % delete_response
            response, keyring = GnomeKeyring.get_info_sync('login')
            if response == GnomeKeyring.Result.OK:
                if keyring is not None:
                    delete_response = GnomeKeyring.delete_sync('login')
                    log.debug('delete login: %s' % delete_response)
                    assert delete_response == GnomeKeyring.Result.OK, \
                        "Delete failed: %s" % delete_response
            elif response != GnomeKeyring.Result.NO_SUCH_KEYRING:
                raise IOError(
                    'Unexpected error when manipulating login keyring')

            # This is result of the underlying DBus error:
            # CKR_WRAPPED_KEY_INVALID, CKR_WRAPPED_KEY_LEN_RANGE,
            # CKR_MECHANISM_PARAM_INVALID
            # So, failed either
            # * egg_padding_pkcs7_unpad
            #   (gnome-keyring/egg/egg-padding.c)
            # * gkm_aes_mechanism_unwrap
            #   (gnome-keyring/pkcs11/gkm/gkm-aes-mechanism.c)
            # * gkm_dh_mechanism_derive
            #   (gnome-keyring/pkcs11/gkm/gkm-dh-mechanism.c)
            # * gkm_null_mechanism_unwrap or gkm_null_mechanism_wrap
            #   (gnome-keyring/pkcs11/gkm/gkm-null-mechanism.c)
            create_response = GnomeKeyring.create_sync('login', 'redhat')
            log.debug('create login: %s' % create_response)
            if create_response != GnomeKeyring.Result.OK:
                raise IOError(
                    'Create failed: %s\n%s' %
                    (create_response,
                     GnomeKeyring.result_to_message(create_response)))

            set_default_response = \
                GnomeKeyring.set_default_keyring_sync('login')
            assert set_default_response == GnomeKeyring.Result.OK, \
                "Set default failed: %s" % set_default_response
        unlock_response = GnomeKeyring.unlock_sync("login", 'redhat')
        assert unlock_response == GnomeKeyring.Result.OK, \
            "Unlock failed: %s" % unlock_response
    except Exception as e:
        log.error("Exception while unlocking a keyring: %s", e.message)
        raise  # We shouldn’t let this exception evaporate
开发者ID:mkrajnak,项目名称:libreoffice-tests,代码行数:58,代码来源:__init__.py

示例5: test_info_unknown

# 需要导入模块: from gi.repository import GnomeKeyring [as 别名]
# 或者: from gi.repository.GnomeKeyring import get_info_sync [as 别名]
    def test_info_unknown(self):
        '''get_info_sync() for unknown keyring'''

        (result, info) = GnomeKeyring.get_info_sync(TEST_KEYRING + '_nonexisting')
        self.assertEqual(result, GnomeKeyring.Result.NO_SUCH_KEYRING)
开发者ID:Bchelz,项目名称:libgnome-keyring,代码行数:7,代码来源:test-gi.py

示例6: isLocked

# 需要导入模块: from gi.repository import GnomeKeyring [as 别名]
# 或者: from gi.repository.GnomeKeyring import get_info_sync [as 别名]
	def isLocked(self):
		info =  GnomeKeyring.get_info_sync(self.keyring)[1]
		return info.get_is_locked()
开发者ID:atareao,项目名称:cryptfolder-indicator,代码行数:5,代码来源:cfkeyringmanager.py

示例7: ungetch

# 需要导入模块: from gi.repository import GnomeKeyring [as 别名]
# 或者: from gi.repository.GnomeKeyring import get_info_sync [as 别名]
        else:
            screen.addstr('\n')

    # Done; pause or eat the key that was ungetch()'d
    screen.addstr('Press any key to continue ...')
    screen.getch()


if __name__ == '__main__':
    gi.require_version('GnomeKeyring', '1.0')
    gi.require_version('Secret', '1')
    from gi.repository import GnomeKeyring as gkr, Secret

    # Unlock the login keyring, if necessary
    was_locked = False
    if gkr.get_info_sync(KEYRING)[1].get_is_locked():
        was_locked = True
        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()
开发者ID:khaeru,项目名称:scripts,代码行数:33,代码来源:gk-query.py


注:本文中的gi.repository.GnomeKeyring.get_info_sync方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。