def get_service_password(service, username, oracle=None, interactive=False):
import getpass<EOL>password = None<EOL>if not oracle or oracle == "<STR_LIT>":<EOL><INDENT>keyring = get_keyring()<EOL>password = keyring.get_password(service, username)<EOL>if interactive and password is None:<EOL><INDENT>oracle = "<STR_LIT>"<EOL>password = get_service_password(service, username,<EOL>oracle, interactive=True)<EOL>if password:<EOL><INDENT>keyring.set_password(service, username, password)<EOL><DEDENT><DEDENT><DEDENT>elif interactive and oracle == "<STR_LIT>":<EOL><INDENT>prompt = "<STR_LIT>" % service<EOL>password = getpass.getpass(prompt)<EOL><DEDENT>elif oracle.startswith('<STR_LIT>'):<EOL><INDENT>command = oracle[<NUM_LIT>:]<EOL>return oracle_eval(command)<EOL><DEDENT>if password is None:<EOL><INDENT>die("<STR_LIT>" %<EOL>(oracle, interactive, service))<EOL><DEDENT>return password<EOL>
Retrieve the sensitive password for a service by:

  * retrieving password from a secure store (@oracle:use_keyring, default)
  * asking the password from the user (@oracle:ask_password, interactive)
  * executing a command and use the output as password
    (@oracle:eval:<command>)

Note that the keyring may or may not be locked
which requires that the user provides a password (interactive mode).

:param service:     Service name, may be key into secure store (as string).
:param username:    Username for the service (as string).
:param oracle:      Hint which password oracle strategy to use.
:return: Retrieved password (as string)

.. seealso::
    https://bitbucket.org/kang/python-keyring-lib