Package wsgitools :: Module digest :: Class DBAPI2NonceStore
[hide private]
[frames] | no frames]

Class DBAPI2NonceStore

source code


A dbapi2-backed nonce store implementation suitable for usage with forking wsgi servers such as scgi.forkpool. >>> import sqlite3 >>> db = sqlite3.connect(":memory:") >>> db.cursor().execute("CREATE TABLE nonces (key, value);") and None >>> db.commit() and None >>> s = DBAPI2NonceStore(db, maxuses=1) >>> n = s.newnonce() >>> s.checknonce("spam") False >>> s.checknonce(n) True >>> s.checknonce(n) False

Instance Methods [hide private]
 
__init__(self, dbhandle, maxage=300, maxuses=5, table='nonces') source code
 
_cleanup(self, cur)
internal methods cleaning list of valid nonces
source code
str
newnonce(self, ident=None)
Generates a new nonce string.
source code
bool
checknonce(self, nonce, count=1, ident=None)
Do a check for whether the provided string is a nonce and increase usage count on returning True.
source code
Method Details [hide private]

__init__(self, dbhandle, maxage=300, maxuses=5, table='nonces')
(Constructor)

source code 
Parameters:
  • dbhandle - is a dbapi2 connection
  • maxage (int) - is the number of seconds a nonce may be valid. Choosing a large value may result in more memory usage whereas a smaller value results in more requests. Defaults to 5 minutes.
  • maxuses (int) - is the number of times a nonce may be used (with different nc values). A value of 1 makes nonces usable exactly once resulting in more requests. Defaults to 5.
Overrides: NonceStoreBase.__init__

newnonce(self, ident=None)

source code 

Generates a new nonce string.

Parameters:
  • ident - is an identifier to be associated with this nonce
Returns: str
Overrides: NonceStoreBase.newnonce

checknonce(self, nonce, count=1, ident=None)

source code 

Do a check for whether the provided string is a nonce and increase usage count on returning True.

Parameters:
  • count (int) - indicates how often the nonce has been used (including this check)
  • ident - it is also checked that the nonce was associated to this identifier when given
  • nonce (str)
Returns: bool
Overrides: NonceStoreBase.checknonce