index 2405a5c2d6306cdd65c035cc276e1ef5c5498a3f..1087967b6096a6d8d0e8e311238c19c378a488e0 100644 (file)
-#$Id: sessions_dbm.py,v 1.5 2004-03-31 23:08:38 richard Exp $
+#$Id: sessions_dbm.py,v 1.10 2008-08-18 05:04:01 richard Exp $
"""This module defines a very basic store that's used by the CGI interface
to store session and one-time-key information.
__docformat__ = 'restructuredtext'
import anydbm, whichdb, os, marshal, time
+from roundup import hyperdb
+from roundup.i18n import _
class BasicDatabase:
''' Provide a nice encapsulation of an anydbm store.
def __init__(self, db):
self.config = db.config
self.dir = db.config.DATABASE
- # ensure files are group readable and writable
- os.umask(0002)
+ os.umask(db.config.UMASK)
def exists(self, infoid):
db = self.opendb('c')
if os.path.exists(path):
db_type = whichdb.whichdb(path)
if not db_type:
- raise hyperdb.DatabaseError, "Couldn't identify database type"
+ raise hyperdb.DatabaseError, \
+ _("Couldn't identify database type")
elif os.path.exists(path+'.db'):
# if the path ends in '.db', it's a dbm database, whether
# anydbm says it's dbhash or not!
pass
def updateTimestamp(self, sessid):
- self.set(sessid, __timestamp=time.time())
-
- def clean(self, now):
- """Age sessions, remove when they haven't been used for a week.
- """
+ ''' don't update every hit - once a minute should be OK '''
+ sess = self.get(sessid, '__timestamp', None)
+ now = time.time()
+ if sess is None or now > sess + 60:
+ self.set(sessid, __timestamp=now)
+
+ def clean(self):
+ ''' Remove session records that haven't been used for a week. '''
+ now = time.time()
week = 60*60*24*7
for sessid in self.list():
sess = self.get(sessid, '__timestamp', None)
if sess is None:
- sess=time.time()
self.updateTimestamp(sessid)
+ continue
interval = now - sess
if interval > week:
self.destroy(sessid)
class OneTimeKeys(BasicDatabase):
name = 'otks'
+# vim: set sts ts=4 sw=4 et si :