Created
November 1, 2017 20:35
-
-
Save srittau/2a467e1932f252f7dcdc30abdf09c36b to your computer and use it in GitHub Desktop.
gnome-keyring Python example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
__version__ = "$Revision: 14294 $" | |
import gtk # ensure that the application name is correctly set | |
import gnomekeyring as gkey | |
class Keyring(object): | |
def __init__(self, name, server, protocol): | |
self._name = name | |
self._server = server | |
self._protocol = protocol | |
self._keyring = gkey.get_default_keyring_sync() | |
def has_credentials(self): | |
try: | |
attrs = {"server": self._servaer, "protocol": self._protocol} | |
items = gkey.find_items_sync(gkey.ITEM_NETWORK_PASSWORD, attrs) | |
return len(items) > 0 | |
except gkey.DeniedError: | |
return False | |
def get_credentials(self): | |
attrs = {"server": self._server, "protocol": self._protocol} | |
items = gkey.find_items_sync(gkey.ITEM_NETWORK_PASSWORD, attrs) | |
return (items[0].attributes["user"], items[0].secret) | |
def set_credentials(self, (user, pw)): | |
attrs = { | |
"user": user, | |
"server": self._server, | |
"protocol": self._protocol, | |
} | |
gkey.item_create_sync(gkey.get_default_keyring_sync(), | |
gkey.ITEM_NETWORK_PASSWORD, self._name, attrs, pw, True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment