# HG changeset patch # User souliane # Date 1411406647 -7200 # Node ID d9c399ec5dd9f3374a98d2649a79250e54c0bbc3 # Parent ed3b01ed70d769d844ad769eed45e2179e3ec93a memory: session timeout won't be reset on each access if the Sessions() is called with resettable_timeout=False diff -r ed3b01ed70d7 -r d9c399ec5dd9 src/memory/memory.py --- 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):