VolatileSessionStore.py

#

A simple in-memory volatile session store, mimicking the default Quixote session management. Here for example’s sake only…

from SessionStore import SessionStore
#

A simple volatile (non-persistent) session store for session3.

class VolatileSessionStore(SessionStore):
#
    is_multiprocess_safe = True
    is_thread_safe = True
#

Create the dictionary.

    def __init__(self):
#
        self.sessions = {}
#

Return the session if it exists, else return ‘default’.

    def load_session(self, id, default=None):
#
        return self.sessions.get(id, default)
#

Save the session in the dictionary..

    def save_session(self, session):
#
        self.sessions[session.id] = session
#

Delete the session in the dictionary.

    def delete_session(self, session):
#
        if self.sessions.has_key(session.id):
            del self.sessions[session.id]
#

Return true if the session exists in the dictionary, else false.

    def has_session(self, id):
#
        return self.sessions.has_key(id)