Changeset 984
- Timestamp:
- 02/28/06 10:05:09
- Files:
-
- trunk/cherrypy/filters/sessionfilter.py (modified) (8 diffs)
- trunk/docs/book/xml/sessions.xml (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/cherrypy/filters/sessionfilter.py
r983 r984 82 82 sess.session_locking = conf('session_filter.locking', 'explicit') 83 83 sess.on_create_session = conf('session_filter.on_create_session', 84 lambda data: None) 85 sess.on_renew_session = conf('session_filter.on_renew_session', 84 86 lambda data: None) 85 87 sess.on_delete_session = conf('session_filter.on_delete_session', … … 264 266 265 267 def load(self, id): 266 file Path = self._getFilePath(id)268 file_path = self._get_file_path(id) 267 269 try: 268 f = open(file Path, "rb")270 f = open(file_path, "rb") 269 271 data = pickle.load(f) 270 272 f.close() … … 274 276 275 277 def save(self, id, data, expiration_time): 276 file Path = self._getFilePath(id)277 f = open(file Path, "wb")278 file_path = self._get_file_path(id) 279 f = open(file_path, "wb") 278 280 pickle.dump((data, expiration_time), f) 279 281 f.close() … … 281 283 def acquire_lock(self): 282 284 sess = cherrypy.request._session 283 file Path = self._getFilePath(cherrypy.session.id)284 lock FilePath = filePath + self.LOCK_SUFFIX285 self._lock File(lockFilePath)285 file_path = self._get_file_path(cherrypy.session.id) 286 lock_file_path = file_path + self.LOCK_SUFFIX 287 self._lock_file(lock_file_path) 286 288 sess.locked = True 287 289 288 290 def release_lock(self): 289 291 sess = cherrypy.request._session 290 file Path = self._getFilePath(cherrypy.session.id)291 lock FilePath = filePath + self.LOCK_SUFFIX292 self._unlock File(lockFilePath)292 file_path = self._get_file_path(cherrypy.session.id) 293 lock_file_path = file_path + self.LOCK_SUFFIX 294 self._unlock_file(lock_file_path) 293 295 sess.locked = False 294 296 … … 303 305 # We have a session file: try to load it and check 304 306 # if it's expired. If it fails, nevermind. 305 file Path = os.path.join(storage_path, fname)307 file_path = os.path.join(storage_path, fname) 306 308 try: 307 f = open(file Path, "rb")309 f = open(file_path, "rb") 308 310 data, expiration_time = pickle.load(f) 309 311 f.close() … … 312 314 id = fname[len(self.SESSION_PREFIX):] 313 315 sess.on_delete_session(data) 314 os.unlink(file Path)316 os.unlink(file_path) 315 317 except: 316 318 # We can't access the file ... nevermind 317 319 pass 318 320 319 def _get FilePath(self, id):321 def _get_file_path(self, id): 320 322 storage_path = cherrypy.config.get('session_filter.storage_path') 321 323 if storage_path is None: 322 324 raise SessionStoragePathNotConfiguredError() 323 325 fileName = self.SESSION_PREFIX + id 324 file Path = os.path.join(storage_path, fileName)325 return file Path326 327 def _lock File(self, path):326 file_path = os.path.join(storage_path, fileName) 327 return file_path 328 329 def _lock_file(self, path): 328 330 sess = cherrypy.request._session 329 331 startTime = time.time() … … 339 341 break 340 342 341 def _unlock File(self, path):343 def _unlock_file(self, path): 342 344 os.unlink(path) 343 345 … … 446 448 # flush session data (but keep the same session_id) 447 449 sess.session_data = {'_id': sess.session_id} 450 if not (data is None): 451 sess.on_renew_session(sess.session_data) 448 452 else: 449 453 sess.session_data = data[0] trunk/docs/book/xml/sessions.xml
r944 r984 87 87 </listitem> 88 88 <listitem> 89 <para><option>session_filter.on_renew_session</option>: See <xref 90 linkend="callbacks" />.</para> 91 </listitem> 92 <listitem> 89 93 <para><option>session_filter.on_delete_session</option>: See <xref 90 94 linkend="callbacks" />.</para> … … 198 202 <para>It is possible to configure the <literal>session_filter</literal> so 199 203 that it calls some special callback functions from your code when sessions 200 are being created/deleted. To do so you have to set the 201 <literal>session_filter.on_create_session</literal> and 204 are being created/renewed/deleted. To do so you have to set the 205 <literal>session_filter.on_create_session</literal>, 206 <literal>session_filter.on_renew_session</literal>, and 202 207 <literal>session_filter.on_delete_session</literal> config options. When a 203 208 session is created/deleted, CherryPy will call these functions and pass

