def get_password(user_name): passwd = None try: with LOCK: store = Keyring() passwd = store.get_password('mail', user_name) except Exception: logging.exception('failed getting password') return passwd
def set_password(user_name): import getpass import keyring passwd = None pw = getpass.getpass('password for %s: ' % (user_name)) if pw: passwd = pw if passwd: try: with LOCK: store = Keyring() store.set_password('mail', user_name, passwd) except Exception: logging.exception('failed setting password') return passwd