7.7.2 SessionBase

The SessionBase class provides base session handling functionality which is used by all standard Albatross execution context session mixin classes.

__init__( )
When you inherit from the SessionBase class you must call this constructor.

The class maintains a dictionary of all names from the execution context local namespace which belong in the session. This dictionary is restored along with the session when the session is decoded.

add_session_vars( ...)
Adds all listed names to the session dictionary. The named variables must exist in the locals member or a SessionError will be raised.

The names can optionally be supplied as a list or tuple of names.

default_session_var( name, value)
Adds a name to the session directory. Sets a value in the local namespace if the name is not already in the local namespace.

del_session_vars( ...)
Deletes all listed names from the session dictionary.

The names can optionally be supplied as a list or tuple of names.

session_vars( )
Returns a list of the names that are currently in the session.

remove_session( )
Deletes all names from the session dictionary and clears all values from the local namespace via the clear_locals() method.

decode_session( text)
Performs cPickle.loads() to retrieve a dictionary of session values. The dictionary is merged into the session local namespace. Adds the keys of the dictionary to the session dictionary.

Just before calling cPickle.loads() the method inserts (and after removes) the application page module directory into sys.path. This allows the pickler to find classes which are defined in application page modules. The page module directory is determined by calling the app.module_path() method.

encode_session( )
Builds a dictionary by extracting all local namespace values which are listed in the session dictionary. A test pickle is performed on each value and any unpickleable value is discarded and an error message is written to sys.stderr.

The dictionary is then passed to cPickle.dumps() and the result is returned.

set_save_session( flag)
Sets the flag which controls whether the session will be saved at the end of request processing. By default the internal flag is TRUE which means the session will be saved.

should_save_session( )
Returns the flag which controls whether the session will be saved at the end of request processing.