7.8.2 SessionFileAppMixin

The application mixin works in concert with the SessionFileContextMixin execution context method to store sessions in the local file-system.

Whenever there are problems reading or writing sessions from or to disk, the class raises a SessionFileError exception, which is a subclass of SessionError. Unless you have a reason to do otherwise, catch SessionError rather than SessionFileError, as this allows other Session classes to be substituted with minimal change.

__init__( appid , session_dir)
When you inherit from the SessionFileAppMixin class you must call this constructor.

The appid argument specifies the name of the cookie attribute which is used to store the session id. This uniquely identifies the application at the web server. Multiple applications can share sessions by defining the same value in this argument.

The session_dir argument specifies the location on the local file-system in which this application's sessions will be stored.

The directory should not be publicly readable, as the session file names are the session id's (knowing a session id allows an attacker to steal that session).

Sessions recorded via this class are not automatically aged. An external process will be required to clean orphaned sessions from the session directory (for example, by removing any file that has not been accessed in the last two hours).

ses_appid( )
Returns the appid argument which was passed to the constructor.

get_session( sesid)
Returns the session identified by sesid argument and the appid passed to the constructor. If no such session exists None is returned.

new_session( )
Returns a new session id for the appid passed to the constructor.

Note that if the session_dir passed to the constructor does not already exist, this method will attempt to create it.

put_session( sesid, text)
Saves the text argument as session data for the session identified by sesid argument and the appid passed to the constructor.

del_session( sesid)
Removes the session identified by sesid argument and the appid passed to the constructor.