Python keyring 模块,delete_password() 实例源码

我们从Python开源项目中,提取了以下15个代码示例,用于说明如何使用keyring.delete_password()

项目:competitive-cli    作者:GDGVIT    | 项目源码 | 文件源码
def delete(self, key):
        key = str(key)
        if key not in self.data["accounts"]:
            print("Account with given index does not exist")
            return
        return_value = self.data["accounts"].pop(key)
        account_keys = [int(indices) for indices in self.data["accounts"].keys() if int(indices)>int(key)]
        for indices in account_keys:
            temp_value = self.data["accounts"].pop(str(indices))
            self.data["accounts"][str(indices-1)] = temp_value

            if self.account == indices: self.account -= 1

        self.number_of_accounts -= 1

        if self.account == int(key): self.account = None
        keyring.delete_password(*return_value)

        return key,return_value
项目:netcrawl    作者:Wyko    | 项目源码 | 文件源码
def test_get_Fernet_returns_a_key():
    fake = Faker()
    appname= '_'.join(['test_a_netcrawl_', fake.word(), fake.word()])
    username= '_'.join(['test_u_netcrawl_', fake.word(), fake.word()])

    key= manage._get_fernet_key(appname, username)

    assert isinstance(key, fernet.Fernet), 'Key [{}] is wrong type'.format(
        type(key))

    assert keyring.get_password(appname, username) is not None

    keyring.delete_password(appname, username)

    assert keyring.get_password(appname, username) is None


#===============================================================================
# def test_check_credentials_no_error():
#     config.cc.check_credentials()
#===============================================================================
项目:competitive-cli    作者:GDGVIT    | 项目源码 | 文件源码
def update(self, key, password):
        key = str(key)
        if key not in self.data["accounts"]:
            print("Account with given index does not exist")
            return
        website, username = self.data["accounts"][key]
        keyring.delete_password(website, username)
        keyring.set_password(website, username, password)
        return
项目:modman    作者:haihala    | 项目源码 | 文件源码
def clear():
        try:
            keyring.delete_password(APP_NAME, getuser())
        except keyring.errors.PasswordDeleteError:
            # Password did not exist, or we have no rights to access it
            # We can just silently ignore this
            pass
项目:mcg    作者:coderkun    | 项目源码 | 文件源码
def on_connection_panel_connection_changed(self, widget, host, port, password, image_dir):
        self._settings.set_string(Window.SETTING_HOST, host)
        self._settings.set_int(Window.SETTING_PORT, port)
        if use_keyring:
            if password:
                keyring.set_password(ZeroconfProvider.KEYRING_SYSTEM, ZeroconfProvider.KEYRING_USERNAME, password)
            else:
                if keyring.get_password(ZeroconfProvider.KEYRING_SYSTEM, ZeroconfProvider.KEYRING_USERNAME):
                   keyring.delete_password(ZeroconfProvider.KEYRING_SYSTEM, ZeroconfProvider.KEYRING_USERNAME)
        self._settings.set_string(Window.SETTING_IMAGE_DIR, image_dir)
项目:onedrived-dev    作者:xybu    | 项目源码 | 文件源码
def delete_account(yes=False, index=None, email=None, account_id=None):
    click.echo('All OneDrive accounts associated with user "%s":\n' % context.user_name)
    all_account_ids = print_all_accounts(context)
    click.echo()

    if index is None and email is None and account_id is None:
        # Print account table and ask which account to delete.
        index = click.prompt('Please enter row number of the account to delete (CTRL+C to abort)', type=int)

    if index is not None:
        if isinstance(index, int) and 0 <= index < len(all_account_ids):
            account_id = all_account_ids[index]
        else:
            error('Index is not a valid row number.')
            return

    if email is not None:
        try:
            account_id = email_to_account_id(context, email, all_account_ids)
        except Exception as e:
            error(str(e))
            return

    if account_id is not None:
        if account_id not in all_account_ids:
            error('Account ID "%s" is not found.' % account_id)
            return
        account = context.get_account(account_id)
        prompt_text = 'Are you sure to delete account %s?' % account
        if yes or click.confirm(prompt_text):
            context.delete_account(account_id)
            keyring.delete_password(OneDriveAPISession.KEYRING_SERVICE_NAME, get_keyring_key(account_id))
            save_context(context)
            success('Successfully deleted account from onedrived.')
        else:
            click.echo('Operation canceled.')
项目:onedrived-dev    作者:xybu    | 项目源码 | 文件源码
def test_save_and_load(self):
        keydict = {self.session.SESSION_ARG_KEYNAME: 'mock_key'}
        self.session.save_session(**keydict)
        session = od_api_session.OneDriveAPISession.load_session(**keydict)
        self.assertEqual(self.session.token_type, session.token_type)
        self.assertEqual(self.session.scope, session.scope)
        self.assertEqual(self.session.access_token, session.access_token)
        self.assertEqual(self.session.client_id, session.client_id)
        self.assertEqual(self.session.client_secret, session.client_secret)
        self.assertEqual(self.session.refresh_token, session.refresh_token)
        keyring.delete_password(od_api_session.OneDriveAPISession.KEYRING_SERVICE_NAME, 'mock_key')
项目:kapsel    作者:conda    | 项目源码 | 文件源码
def unset(env_prefix, variable):
    name = _make_username(env_prefix, variable)
    if not _use_fallback_keyring():
        try:
            keyring.delete_password("anaconda", name)
            return
        except Exception as e:
            # keyring throws a bare "RuntimeError" if it has no working backend;
            # not sure what else it can throw.
            _onetime_keyring_complain_and_disable("Exception deleting a password: " + str(e))

    # on either exception, or disabled
    if name in _fake_in_memory_keyring:
        del _fake_in_memory_keyring[name]
项目:jira_reporting_scripts    作者:andrew-hamlin-sp    | 项目源码 | 文件源码
def clear_credentials(username):
    if username and keyring.get_keyring():
        try:
            keyring.delete_password(KEYRING_NAME, username)
        except keyring.errors.PasswordDeleteError as err:
            Log.error(err)
项目:got    作者:mrozekma    | 项目源码 | 文件源码
def delete(self):
        keyring.delete_password(self.host_name, self.username)

# Point the name 'Credential' at the keyring class if a system keyring is available, or the DB class if not
# The DB interface has extra methods since it's an ActiveRecord, but they shouldn't be used since the keyring interface might be active
项目:biweeklybudget    作者:jantman    | 项目源码 | 文件源码
def write(self, *args):
        """See ConfigParser.write().  Also writes secure items to keystore."""
        ConfigParser.write(self, *args)
        if self.keyring_available:
            for key, thing in self._unsaved.items():
                action = thing[0]
                value = thing[1]
                if action == 'set':
                    keyring.set_password(self.keyring_name, key, value)
                elif action == 'delete':
                    try:
                        keyring.delete_password(self.keyring_name, key)
                    except:
                        pass
        self._unsaved = {}
项目:mrt_tools    作者:KIT-MRT    | 项目源码 | 文件源码
def delete(self, key):
        try:
            keyring.delete_password(self.SERVICE_NAME, key)
            click.secho("Removed {} from keyring".format(key), fg="green")
        except keyring.errors.PasswordDeleteError:
            pass
项目:anaconda-project    作者:Anaconda-Platform    | 项目源码 | 文件源码
def unset(env_prefix, variable):
    name = _make_username(env_prefix, variable)
    if not _use_fallback_keyring():
        try:
            keyring.delete_password("anaconda", name)
            return
        except Exception as e:
            # keyring throws a bare "RuntimeError" if it has no working backend;
            # not sure what else it can throw.
            _onetime_keyring_complain_and_disable("Exception deleting a password: " + str(e))

    # on either exception, or disabled
    if name in _fake_in_memory_keyring:
        del _fake_in_memory_keyring[name]
项目:flik    作者:rsteube    | 项目源码 | 文件源码
def logout():
    keyring.delete_password('flik', config.load()['username'])
    client().service.Logout(sessionID())
项目:homeassistant    作者:NAStools    | 项目源码 | 文件源码
def run(args):
    """Handle keyring script."""
    parser = argparse.ArgumentParser(
        description=("Modify Home-Assistant secrets in the default keyring. "
                     "Use the secrets in configuration files with: "
                     "!secret <name>"))
    parser.add_argument(
        '--script', choices=['keyring'])
    parser.add_argument(
        'action', choices=['get', 'set', 'del', 'info'],
        help="Get, set or delete a secret")
    parser.add_argument(
        'name', help="Name of the secret", nargs='?', default=None)

    import keyring
    from keyring.util import platform_ as platform

    args = parser.parse_args(args)

    if args.action == 'info':
        keyr = keyring.get_keyring()
        print('Keyring version {}\n'.format(keyring.__version__))
        print('Active keyring  : {}'.format(keyr.__module__))
        config_name = os.path.join(platform.config_root(), 'keyringrc.cfg')
        print('Config location : {}'.format(config_name))
        print('Data location   : {}\n'.format(platform.data_root()))
    elif args.name is None:
        parser.print_help()
        return 1

    if args.action == 'set':
        the_secret = getpass.getpass('Please enter the secret for {}: '
                                     .format(args.name))
        keyring.set_password(_SECRET_NAMESPACE, args.name, the_secret)
        print('Secret {} set successfully'.format(args.name))
    elif args.action == 'get':
        the_secret = keyring.get_password(_SECRET_NAMESPACE, args.name)
        if the_secret is None:
            print('Secret {} not found'.format(args.name))
        else:
            print('Secret {}={}'.format(args.name, the_secret))
    elif args.action == 'del':
        try:
            keyring.delete_password(_SECRET_NAMESPACE, args.name)
            print('Deleted secret {}'.format(args.name))
        except keyring.errors.PasswordDeleteError:
            print('Secret {} not found'.format(args.name))