Back to index

plone3  3.1.7
keyring.py
Go to the documentation of this file.
00001 import random
00002 from zope.interface import implements
00003 from persistent.list import PersistentList
00004 from plone.keyring.interfaces import IKeyring
00005 from zope.app.container.contained import Contained
00006 
00007 def GenerateSecret(length=64):
00008     secret=""
00009     for i in range(length):
00010         secret+=chr(random.getrandbits(8))
00011 
00012     return secret
00013 
00014 
00015 class Keyring(PersistentList, Contained):
00016     implements(IKeyring)
00017 
00018     def __init__(self, size=5):
00019         PersistentList.__init__(self)
00020         for i in range(size):
00021             self.append(None)
00022 
00023     def __iter__(self):
00024         for item in self.data:
00025             yield item
00026 
00027     def clear(self):
00028         for i in range(len(self)):
00029             self[i]=None
00030 
00031     def rotate(self):
00032         self.pop()
00033         self.insert(0, GenerateSecret())
00034 
00035     @property
00036     def current(self):
00037         return self.data[0]
00038 
00039 
00040 
00041 
00042