Store sessions in a Durus database.
import os, os.path
from session3.store.SessionStore import SessionStore
from durus.persistent_dict import PersistentDict
A session store for Durus, a simple object database.
Unlike the dulcinea Durus session store, session objects themselves are not subclasses of Persistent; here they are managed by DurusSessionStore directly.
class DurusSessionStore(SessionStore):
is_multiprocess_safe = True
is_thread_safe = False # Durus is not thread safe.
init takes a Durus connection
object.
def __init__(self, connection):
self.connection = connection
root = connection.get_root()
sessions_dict = root.get('sessions')
if sessions_dict is None:
sessions_dict = PersistentDict()
root['sessions'] = sessions_dict
connection.commit()
self.sessions_dict = sessions_dict
Load the session from the shelf.
def load_session(self, id, default=None):
self.connection.abort()
return self.sessions_dict.get(id, default)
Delete the given session from the shelf.
def delete_session(self, session):
del self.sessions_dict[session.id]
self.connection.commit()
Save the session to the shelf.
def save_session(self, session):
self.sessions_dict[session.id] = session
self.connection.commit()