Mercurial > libervia-backend
changeset 1215:d9c399ec5dd9
memory: session timeout won't be reset on each access if the Sessions() is called with resettable_timeout=False
author | souliane <souliane@mailoo.org> |
---|---|
date | Mon, 22 Sep 2014 19:24:07 +0200 |
parents | ed3b01ed70d7 |
children | 8ad37c3d58a9 |
files | src/memory/memory.py |
diffstat | 1 files changed, 9 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/src/memory/memory.py Mon Sep 22 18:42:54 2014 +0200 +++ b/src/memory/memory.py Mon Sep 22 19:24:07 2014 +0200 @@ -40,12 +40,14 @@ """Sessions are data associated to key used for a temporary moment, with optional profile checking.""" DEFAULT_TIMEOUT = 600 - def __init__(self, timeout=None): + def __init__(self, timeout=None, resettable_timeout=True): """ - @param timeout: nb of seconds before session destruction + @param timeout (int): nb of seconds before session destruction + @param resettable_timeout (bool): if True, the timeout is reset on each access """ self._sessions = dict() self.timeout = timeout or Sessions.DEFAULT_TIMEOUT + self.resettable_timeout = resettable_timeout def newSession(self, session_data=None, session_id=None, profile=None): """ Create a new session @@ -83,7 +85,8 @@ raise exceptions.InternalError("You need to use __getitem__ when profile is not set") if profile_set != profile: raise exceptions.InternalError("current profile differ from set profile !") - timer.reset(self.timeout) + if self.resettable_timeout: + timer.reset(self.timeout) return session_data def __getitem__(self, session_id): @@ -91,7 +94,8 @@ timer, session_data = self._sessions[session_id] except ValueError: raise exceptions.InternalError("You need to use profileGet instead of __getitem__ when profile is set") - timer.reset(self.timeout) + if self.resettable_timeout: + timer.reset(self.timeout) return session_data def __setitem__(self, key, value): @@ -146,7 +150,7 @@ ids = self._profileGetAllIds(profile) if len(ids) > 1: raise exceptions.InternalError('profileGetUnique has been used but more than one session has been found!') - return self.profileGet(ids[0], profile) if len(ids) == 1 else None + return self.profileGet(ids[0], profile) if len(ids) == 1 else None # XXX: timeout might be reset def profileDelUnique(self, profile):