duck.http.session.engine

Module representing Duck default session engine, i.e. SessionStore class.

Module Contents

Classes

SessionStore

Session store for storing session data.

Data

session_connector_mod

API

exception duck.http.session.engine.SessionError[source]

Bases: Exception

Session related errors.

Initialization

Initialize self. See help(type(self)) for accurate signature.

exception duck.http.session.engine.SessionExpired[source]

Bases: duck.http.session.engine.SessionError

Raised on save operations if a session has already expired.

Initialization

Initialize self. See help(type(self)) for accurate signature.

class duck.http.session.engine.SessionStore(session_key: str, disable_warnings: bool = False)[source]

Bases: dict

Session store for storing session data.

Initialization

Initializes the session store.

__delitem__(key)[source]
__getitem__(key)[source]
__repr__()[source]
__setitem__(key, value)[source]
__slots__

None

_save()[source]

Saves the session to storage.

assign_new_session_key() str[source]

Creates a new session with a new session key.

async async_save()[source]

Asynchronously save session.

static check_session_storage_connector(method)[source]

Decorator to ensure a valid session storage connector is present.

Validates: - Attribute exists - Attribute is not None - Attribute is correct type

clear()[source]

Clears all session data.

delete(session_key: Optional[str] = None)[source]

Deletes and clears the session from session storage.

Parameters:

session_key – The session key or None if you want to use the current session key.

static ensure_session_loaded(method)[source]

Decorator which ensures that the session is loaded.

exists(session_key: Optional[str] = None) bool[source]

Checks if a session with the specified key exists.

Parameters:

session_key – The session key or None if you want to use the current session key.

static generate_session_id() str[source]

Generates and returns a random session ID.

get(*args, **kw)[source]

Return value for a key.

get_expiry_age()[source]

Returns the session max age from current settings.

get_expiry_date()[source]

Returns the datetime the session is going to expire.

load() dict[source]

Loads the session from storage.

property loaded: bool

Returns the state whether the session has been loaded.

property modified: bool

Returns the state whether the session has been modified after load or creation.

needs_update() bool[source]

Returns whether the session data is worthy to be saved, this is the lazy behavior of Duck.

pop(*args, **kwargs)[source]

Pops some session data.

popitem(*args, **kwargs)[source]

Pops some session data.

save()[source]

Save the session

session_expired() bool[source]

Returns boolean on whether if the session has expired depending on expiry set on session.

property session_key
set_expiry(expiry: Optional[Union[int, float, datetime.datetime, datetime.timedelta]] = None)[source]

Sets the session expiry.

Parameters:
  • Optional[Union[int (expiry) – Float or int represents the seconds to expire from now and None represents the now plus the default session max_age.

  • float – Float or int represents the seconds to expire from now and None represents the now plus the default session max_age.

  • datetime.datetime – Float or int represents the seconds to expire from now and None represents the now plus the default session max_age.

  • datetime.timedelta]] – Float or int represents the seconds to expire from now and None represents the now plus the default session max_age.

update(data: dict)[source]

Overrides the update method to ensure items are tracked for modification.

duck.http.session.engine.session_connector_mod

‘import_module_once(…)’