watson.http.sessions.abc

class watson.http.sessions.abc.StorageMixin(id=None, timeout=None, autosave=True)[source]

The base mixin for all session storage adapters.

By default, if no id is specified when the session is created a new session id will be generated. When a user is logged in, it is good practice to regenerate the id of the session id to prevent session hijacking.

If autosave is set to True, then when data is added to the session the save() method will be called. If set to False, the developer will be required to manually call the save() method themselves.

To function correctly sessions require that cookies are enabled in the users browser.

Example:

session = SessionStorageMethod()
# where SessionStorageMethod is a valid storage class
session['key'] = 'some value'
session['key'] # 'some value'
__init__(id=None, timeout=None, autosave=True)[source]
Parameters:
  • id – the id of the session
  • timeout – the expiry time from the current time in seconds
  • key – the key used to reference the session id in a cookie
  • autosave – save the contents on __setitem__
cookie_params

The cookie params used when saving the session id as a cookie.

data

The data associated with the session.

destroy()[source]

Destroy the session data from storage, but leave the actual session intact.

exists()[source]

Determine whether or not the session exists in storage.

Returns:Boolean whether or not the session id exists.
generate_id()[source]
Returns:A new session id based on a random 24 char string
id

The id of the session.

load()[source]

Loads the data from storage into the session. If the session data was set to expire before the current time, destroy the session.

regenerate_id()[source]

Regenerate a new id for the session.

save()[source]

Save the contents of the session into storage.

watson.http.sessions.abc.random() → x in the interval [0, 1).