nagare.sessions package

Submodules

nagare.sessions.common module

Base classes for the sessions management

class nagare.sessions.common.Sessions(states_history=True, security_cookie_httponly=True, security_cookie_name='_nagare', security_cookie_secure=False, serializer=<class 'nagare.sessions.serializer.Dummy'>, pickler=None, unpickler=None)

Bases: object

The sessions managers

check_session_id(session_id)

Test if a session exist

In:
  • session_id – id of a session
Return:
  • is session_id the id of an existing session?
create(session_id, secure_id, lock)

Create a new session

In:
  • session_id – id of the session
  • secure_id – the secure number associated to the session
  • lock – the lock of the session
create_lock(session_id)

Create a new lock for a session

In:
  • session_id – session id
Return:
  • the lock
delete(session_id)

Delete a session

In:
  • session_id – id of the session to delete
fetch_state(session_id, state_id)

Retrieve a state with its associated objects graph

In:
  • session_id – session id of this state
  • state_id – id of this state
Return:
  • id of the more recent stored state
  • secure number associated to the session
  • data kept into the session
  • data kept into the state
get_lock(session_id)

Retrieve the lock of a session

In:
  • session_id – session id
Return:
  • the lock
get_root(session_id, state_id)

Retrieve the objects graph of a state

In:
  • session_id – session id of this state
  • state_id – id of this state
Return:
  • id of the latest state
  • secure number associated to the session
  • objects graph
get_state(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 created?
Return:
  • the state
sessionid_in_form(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
sessionid_in_url(session_id, state_id, request, response)

Return the session and states ids to put into an URL

In:
  • request – the web request
  • response – the web response
Return:
  • session id parameter
  • state id parameter (optional, only if states_history is True)
set_config(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
set_root(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 a copy of this state to be created?
  • data – the objects graph
spec = {'pickler': 'string(default="cPickle:Pickler")', 'unpickler': 'string(default="cPickle:Unpickler")', 'states_history': 'boolean(default=True)', 'security_cookie_secure': 'boolean(default=False)', 'security_cookie_httponly': 'boolean(default=True)', 'security_cookie_name': 'string(default="_nagare")', 'serializer': 'string(default="nagare.sessions.serializer:Dummy")'}
store_state(session_id, state_id, secure_id, use_same_state, session_data, state_data)

Store a state and its associated objects graph

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?
  • session_data – data to keep into the session
  • state_data – data to keep into the state
class nagare.sessions.common.State(sessions_manager, session_id, state_id, secure_id, use_same_state)

Bases: object

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

acquire()

Lock the state

delete()

Delete the session of this state

get_root()

Retrieve the objects graph of this state

Return:
  • the objects graph (None if this state is new)
release()

Release the state

sessionid_in_form(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
  • response – the web response
Return:
  • the DOM tree
sessionid_in_url(request, response)

Return the session and states ids to put into an URL

In:
  • request – the web request
  • response – the web response
Return:
  • session id parameter
  • state id parameter
set_root(use_same_state, data)

Store the objects graph of this state

In:
  • use_same_state – is the objects graph to be stored in this state or in a new one?
  • data – the objects graph

nagare.sessions.lru_dict module

A LRU dictionary is a dictionary with a fixed maximum number of keys.

When this maximum is reached, the last recently used key is deleted when a new key is added.

class nagare.sessions.lru_dict.LRUDict(size)

Bases: object

A LRU dictionary is a dictionary with a fixed maximum number of keys

debug()
class nagare.sessions.lru_dict.ThreadSafeLRUDict(*args, **kw)

Bases: nagare.sessions.lru_dict.LRUDict

Tread safe version of a LRU dictionary

nagare.sessions.memcached_sessions module

class nagare.sessions.memcached_sessions.Lock(connection, lock_id, ttl, poll_time, max_wait_time)

Bases: object

acquire()

Acquire the lock

release()

Release the lock

class nagare.sessions.memcached_sessions.Sessions(host='127.0.0.1', port=11211, ttl=0, lock_ttl=0, lock_poll_time=0.1, lock_max_wait_time=5, min_compress_len=0, reset=False, debug=True, serializer=None, **kw)

Bases: nagare.sessions.common.Sessions

Sessions manager for sessions kept in an external memcached server

create(session_id, secure_id, lock)

Create a new session

In:
  • session_id – id of the session
  • secure_id – the secure number associated to the session
  • lock – the lock of the session
delete(session_id)

Delete a session

In:
  • session_id – id of the session to delete
fetch_state(session_id, state_id)

Retrieve a state with its associated objects graph

In:
  • session_id – session id of this state
  • state_id – id of this state
Return:
  • id of the latest state
  • secure number associated to the session
  • data kept into the session
  • data kept into the state
flush_all()

Delete all the contents in the memcached server

get_lock(session_id)

Retrieve the lock of a session

In:
  • session_id – session id
Return:
  • the lock
set_config(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
spec = {'lock_max_wait_time': 'float(default=5.)', 'min_compress_len': 'integer(default=0)', 'lock_ttl': 'float(default=0.)', 'host': 'string(default="127.0.0.1")', 'ttl': 'integer(default=0)', 'security_cookie_httponly': 'boolean(default=True)', 'pickler': 'string(default="cPickle:Pickler")', 'port': 'integer(default=11211)', 'reset': 'boolean(default=True)', 'unpickler': 'string(default="cPickle:Unpickler")', 'states_history': 'boolean(default=True)', 'lock_poll_time': 'float(default=0.1)', 'security_cookie_secure': 'boolean(default=False)', 'debug': 'boolean(default=False)', 'security_cookie_name': 'string(default="_nagare")', 'serializer': 'string(default="nagare.sessions.serializer:Pickle")'}
store_state(session_id, state_id, secure_id, use_same_state, session_data, state_data)

Store a state and its associated objects graph

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?
  • session_data – data to keep into the session
  • state_data – data to keep into the state

nagare.sessions.memory_sessions module

Sessions managed in memory

These sessions managers keep:
  • the last recently used DEFAULT_NB_SESSIONS sessions
  • for each session, the last recently used DEFAULT_NB_STATES states
class nagare.sessions.memory_sessions.Sessions(nb_sessions=10000, nb_states=20, **kw)

Bases: nagare.sessions.common.Sessions

Sessions manager for states kept in memory

check_session_id(session_id)

Test if a session exist

In:
  • session_id – id of a session
Return:
  • is session_id the id of an existing session?
create(session_id, secure_id, lock)

Create a new session

In:
  • session_id – id of the session
  • secure_id – the secure number associated to the session
  • lock – the lock of the session
create_lock(session_id)

Create a new lock for a session

In:
  • session_id – session id
Return:
  • the lock
delete(session_id)

Delete a session

In:
  • session_id – id of the session to delete
fetch_state(session_id, state_id)

Retrieve a state with its associated objects graph

In:
  • session_id – session id of this state
  • state_id – id of this state
Return:
  • id of the latest state
  • secure number associated to the session
  • data kept into the session
  • data kept into the state
get_lock(session_id)

Retrieve the lock of a session

In:
  • session_id – session id
Return:
  • the lock
set_config(filename, conf, error)

Read the configuration parameters

In:
  • filename – path to the configuration file
  • confConfigObj object created from the configuration file
  • error – function to call in case of configuration errors
spec = {'security_cookie_name': 'string(default="_nagare")', 'security_cookie_secure': 'boolean(default=False)', 'security_cookie_httponly': 'boolean(default=True)', 'unpickler': 'string(default="cPickle:Unpickler")', 'pickler': 'string(default="cPickle:Pickler")', 'nb_states': 'integer(default=20)', 'states_history': 'boolean(default=True)', 'serializer': 'string(default="nagare.sessions.serializer:Dummy")', 'nb_sessions': 'integer(default=10000)'}
store_state(session_id, state_id, secure_id, use_same_state, session_data, state_data)

Store a state and its associated objects graph

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?
  • session_data – data to keep into the session
  • state_data – data to keep into the state
class nagare.sessions.memory_sessions.SessionsWithPickledStates(serializer=None, **kw)

Bases: nagare.sessions.memory_sessions.Sessions

Sessions manager for states pickled / unpickled in memory

spec = {'pickler': 'string(default="cPickle:Pickler")', 'unpickler': 'string(default="cPickle:Unpickler")', 'states_history': 'boolean(default=True)', 'security_cookie_secure': 'boolean(default=False)', 'security_cookie_httponly': 'boolean(default=True)', 'security_cookie_name': 'string(default="_nagare")', 'nb_states': 'integer(default=20)', 'serializer': 'string(default="nagare.sessions.serializer:Pickle")', 'nb_sessions': 'integer(default=10000)'}

nagare.sessions.serializer module

class nagare.sessions.serializer.Dummy(pickler=None, unpickler=None)

Bases: object

dumps(data, clean_callbacks)

Serialize an objects graph

In:
  • data – the objects graph
  • clean_callbacks – do we have to forget the old callbacks?
Out:
  • data kept into the session
  • data kept into the state
loads(session_data, state_data)

Deserialize an objects graph

In:
  • session_data – data from the session
  • state_data – data from the state
Out:
  • the objects graph
  • the callbacks
class nagare.sessions.serializer.DummyFile

Bases: object

A write-only file that does nothing

write(data)
class nagare.sessions.serializer.Pickle(pickler=None, unpickler=None)

Bases: nagare.sessions.serializer.Dummy

dumps(data, clean_callbacks)

Serialize an objects graph

In:
  • data – the objects graph
  • clean_callbacks – do we have to forget the old callbacks?
Out:
  • data kept into the session
  • data kept into the state
loads(session_data, state_data)

Deserialize an objects graph

In:
  • session_data – data from the session
  • state_data – data from the state
Out:
  • the objects graph
  • the callbacks
nagare.sessions.serializer.persistent_id(o, clean_callbacks, callbacks, session_data, tasklets)

An object with a _persistent_id attribute is stored into the session not into the state snapshot

In:
  • o – object to check
  • clean_callbacks – do we have to forget the old callbacks?
Out:
  • callbacks – merge of the callbacks from all the components
  • session_data – dict persistent_id -> object of the objects to store into the session
  • tasklets – set of the serialized tasklets
Return:
  • the persistent id or None
nagare.sessions.serializer.set_persistent_id(pickler, persistent_id)

Module contents

exception nagare.sessions.ExpirationError

Bases: exceptions.LookupError

Raised when a session or a state id is no longer valid

exception nagare.sessions.SessionSecurityError

Bases: exceptions.LookupError

Raised when the secure id of a session is not valid