Module common

Base classes for the sessions management

Imports:
cPickle, cStringIO, configobj, nagare, nagare.admin, nagare.sessions, random, stackless
Classes:
Sessions(object): The sessions managers
State(object): A state (objects graph serialized / deserialized by a sessions manager)
Methods:
persistent_id(o, session_data, tasklets): The object with a _persistent_id attribute are stored into the session not into the state snapshot

Class common.Sessions

Back to common

Bases:
object

The sessions managers

Methods:
__init__(self, states_history=True, pickler=cPickle.Pickler, unpickler=cPickle.Unpickler, security_cookie_name='_nagare'): Initialization
_get_ids(self, request): Search the session id and the state id into the request parameters
create_state(self, session_id, secure_id): Initialized a new state, with an empty objects graph
delete(self, session_id): Delete the session
get(self, request, response, use_same_state): Create a new state or return an existing one
get_state(self, session_id, state_id, use_same_state): Retrieve the state
is_session_exist(self, session_id): Test if a session id is invalid
pickle(self, data): Pickle an objects graph
sessionid_in_form(self, session_id, state_id, h, request, response): Return the DOM tree to merge into a form to add the session and state hidden ids
sessionid_in_url(self, session_id, state_id, request, response): Return the session and states ids to put into an URL
set(self, state, use_same_state): Store the state
set_config(self, filename, conf, error): Read the configuration parameters
set_state(self, session_id, state_id, secure_id, use_same_state, data): Store the state
unpickle(self, session_data, state_data): Unpickle an objects graph
Attributes:
spec = { 'security_cookie_name' : 'string(default="_nagare")', 'states_history' : 'boolean(default=True)', 'pickler' : 'string(default="cPickle:Pickler")', 'unpickler' : 'string(default="cPickle:Unpickler")' }

Method common.Sessions.__init__

Back to common.Sessions

Arguments:
self, states_history=True, pickler=cPickle.Pickler, unpickler=cPickle.Unpickler, security_cookie_name='_nagare'

Initialization

In:
  • security_cookie_name -- name of the cookie where the session secure id is stored

Method common.Sessions._get_ids

Back to common.Sessions

Arguments:
self, request

Search the session id and the state id into the request parameters

In:
  • request -- the web request object
Return:
  • a tuple (session id, state id) or ('', '') if no session found

Method common.Sessions.create_state

Back to common.Sessions

Arguments:
self, session_id, secure_id

Initialized a new state, with an empty objects graph

In:
  • session_id -- session id of this state
  • secure_id -- the secure number associated to the session
Return:
  • the tuple: - id of this state, - session lock

Method common.Sessions.delete

Back to common.Sessions

Arguments:
self, session_id

Delete the session

In:
  • session_id -- session id of this state

Method common.Sessions.get

Back to common.Sessions

Arguments:
self, request, response, use_same_state

Create a new state or return an existing one

In:
  • request -- the web request object
  • response -- the web response object
  • use_same_state -- is a copy of the state to create ?
Return:
  • the state object

Method common.Sessions.get_state

Back to common.Sessions

Arguments:
self, session_id, state_id, use_same_state

Retrieve the state

In:
  • session_id -- session id of this state
  • state_id -- id of this state
  • use_same_state -- is a copy of this state to create ?
Return:
  • the tuple: - id of this state, - session lock, - secure number associated to the session, - objects graph

Method common.Sessions.is_session_exist

Back to common.Sessions

Arguments:
self, session_id

Test if a session id is invalid

In:
  • session_id -- id of the session
Return:
  • a boolean

Method common.Sessions.pickle

Back to common.Sessions

Arguments:
self, data

Pickle an objects graph

In:
  • data -- the objects graph
Out:
  • the tuple: - data to keep into the session - data to keep into the state

Method common.Sessions.sessionid_in_form

Back to common.Sessions

Arguments:
self, session_id, state_id, h, request, response

Return the DOM tree to merge into a form to add the session and state hidden ids

In:
  • h -- the current renderer
  • request -- the web request object
  • response -- the web response object
Return:
  • a DOM tree

Method common.Sessions.sessionid_in_url

Back to common.Sessions

Arguments:
self, session_id, state_id, request, response

Return the session and states ids to put into an URL

In:
  • request -- the web request object
  • response -- the web response object
Return:
  • tuple (session id parameter, state id parameter)

Method common.Sessions.set

Back to common.Sessions

Arguments:
self, state, use_same_state

Store the state

In:
  • state -- the state object
  • use_same_state -- is a copy of this state to create ?

Method common.Sessions.set_config

Back to common.Sessions

Arguments:
self, filename, conf, error

Read the configuration parameters

In:
  • filename -- the path to the configuration file
  • conf -- the ConfigObj object, created from the configuration file
  • error -- the function to call in case of configuration errors

Method common.Sessions.set_state

Back to common.Sessions

Arguments:
self, session_id, state_id, secure_id, use_same_state, data

Store the state

In:
  • session_id -- session id of this state
  • state_id -- id of this state
  • secure_id -- the secure number associated to the session
  • use_same_state -- is this state to be stored in the previous snapshot ?
  • data -- the objects graph

Method common.Sessions.unpickle

Back to common.Sessions

Arguments:
self, session_data, state_data

Unpickle an objects graph

In:
  • session_data -- data from the session
  • state_data -- data from the state
Out:
  • the objects graph

Class common.State

Back to common

Bases:
object

A state (objects graph serialized / deserialized by a sessions manager)

Methods:
__init__(self, sessions_manager, session_id, state_id, use_same_state): Initialization
create(self, secure_id): Initialized a new state, with an empty objects graph
delete(self): Delete this state
get(self): Retrieve the state
release(self): Release the session lock
sessionid_in_form(self, h, request, response): Return the DOM tree to merge into a form, to add the session and state hidden ids
sessionid_in_url(self, request, response): Return the session and states ids to put into an URL
set(self, use_same_state, data): Store the state

Method common.State.__init__

Back to common.State

Arguments:
self, sessions_manager, session_id, state_id, use_same_state

Initialization

In:
  • sessions_manager -- the session manager of this state
  • session_id -- session id of this state
  • state_id -- id of this state
  • use_same_state -- is a copy of this state to create ?

Method common.State.create

Back to common.State

Arguments:
self, secure_id

Initialized a new state, with an empty objects graph

In:
  • secure_id -- the secure number associated to the session

Method common.State.get

Back to common.State

Arguments:
self

Retrieve the state

Return:
  • secure_id -- the secure number associated to the session

Method common.State.sessionid_in_form

Back to common.State

Arguments:
self, h, request, response

Return the DOM tree to merge into a form, to add the session and state hidden ids

In:
  • h -- the current renderer
  • request -- the web request object
  • response -- the web response object
Return:
  • the DOM tree

Method common.State.sessionid_in_url

Back to common.State

Arguments:
self, request, response

Return the session and states ids to put into an URL

In:
  • request -- the web request object
  • response -- the web response object
Return:
  • tuple (session id parameter, state id parameter)

Method common.State.set

Back to common.State

Arguments:
self, use_same_state, data

Store the state

In:
  • use_same_state -- is this state to be stored in the previous snapshot ?
  • data -- the objects graph

Method common.persistent_id

Back to common

Arguments:
o, session_data, tasklets

The object with a _persistent_id attribute are stored into the session not into the state snapshot

In:
  • o -- object to check
Out:
  • session_data -- dict of the objects to store into the session
  • tasklets -- set of the serialized tasklets