There's already a pototype demo in our demo folder(demo/keyring_demo.py). Here's some snippets from the demo.
KEYRINGRC = ".keyringrc"
def load_keyring_by_config():
"""
This function shows how to enable a keyring using config file
"""
# create the config file
f = open(KEYRINGRC,'w')
f.writelines(["[backend]\n",
# the path for the user created keyring
"keyring-path= %s\n" % str(os.path.abspath(__file__))[:-16],
# the name of the keyring class
"default-keyring=simplekeyring.SimpleKeyring\n" ])
f.close()
# import the keyring lib, the lib will automaticlly load the
# config file and load the user defined module
import keyring
# invoke the keyring to store and fetch the password
if keyring.setpass("demo-service","tarek","passexample") == 0:
print "password stored sucessful"
print "password", keyring.getpass("demo-service","tarek")
os.remove(KEYRINGRC)
def set_keyring_in_runtime():
"""
This function shows how to create a keyring manully and use it in runtime
"""
# define a new keyring class which extends the KeyringBackend
import keyring.backend
class TestKeyring(keyring.backend.KeyringBackend):
def setpass(self,servicename,username,password): return 0
def getpass(self,servicename,username): return "password from TestKeyring"
# set the keyring for keyring lib
import keyring
keyring.set_keyring(TestKeyring())
# invoke the keyring lib
if keyring.setpass("demo-service","tarek","passexample") == 0:
print "password stored successful"
print "password", keyring.getpass("demo-service","tarek")
That two funtions illustrate the process of enabling a user created keyring by the config file and set the keyring in the runtime. The keyring class that load from disk is stored in demo/simplekeyring.py. Here's the definition of the keyring class.
class SimpleKeyring(KeyringBackend):
"""Simple Keyring is a keyring which can store only one
password in memory.
"""
def __init__(self):
self.password = ''
def getpass(self,servicename,username):
return self.password
def setpass(self,servicename,username,password):
print "calling SimpleKeyring.setpass()"
self.password = password
return 0
For more details, please refer to our repository
1 comments:
If you want to build a stunning statement, the dragonfly design of the Coach Purses constructs the correct alternative for you. It is obtainable in a variety of alternatives, such as the Coach Legacy Optic with dragonfly and the Coach Luggage . You belong to the 21st century and if you want to make heads revolve, you have to buy dragonfly Coach Madison .
With today wide range of online wholesale SUDDENLY SUSAN store options you can select from a huge amount of sellers online. You can go to eBay right now and get brand new SUDDENLY SUSAN DVD COLLECTION at good prices, but are eBay prices the best SUDDENLY SUSAN DVD prices you can get on the Internet?
It is not anymore the perception that Hogan functions is more important than Hogan uomo style when you are looking for Hogan scarpe donna . So, what are you waiting for when you can enjoy both the performance and stylishness? Hogan scarpe uomo is the most popular among young generation that blends fashion with sports
Post a Comment