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
>>> n = s.newnonce()
>>> s.checknonce(n.rsplit(':', 1)[0] + "bad hash")
False
Instance Methods [hide private]
 
__init__(self, dbhandle, maxage=300, maxuses=5, table='nonces')
x.__init__(...) initializes x; see help(type(x)) for signature
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

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

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

source code 

x.__init__(...) initializes x; see help(type(x)) for signature

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: object.__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 (str or None) - it is also checked that the nonce was associated to this identifier when given
  • nonce (str)
Returns: bool
Overrides: NonceStoreBase.checknonce