Changeset 1287
- Timestamp:
- 08/26/06 21:12:23
- Files:
-
- trunk/cherrypy/lib/sessions.py (modified) (6 diffs)
- trunk/cherrypy/test/test_session.py (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/cherrypy/lib/sessions.py
r1280 r1287 118 118 t.start() 119 119 120 def delete(self): 121 """Delete stored session data.""" 122 self._delete() 123 120 124 def __getitem__(self, key): 121 125 if not self.loaded: self.load() … … 188 192 def _save(self, expiration_time): 189 193 self.cache[self.id] = (self._data, expiration_time) 194 195 def _delete(self): 196 del self.cache[self.id] 190 197 191 198 def acquire_lock(self): … … 225 232 finally: 226 233 f.close() 234 235 def _delete(self): 236 os.unlink(self._get_file_path()) 227 237 228 238 def acquire_lock(self, path=None): … … 304 314 305 315 def _save(self, expiration_time): 316 pickled_data = pickle.dumps(self._data) 317 self.cursor.execute('update session set data = %s, ' 318 'expiration_time = %s where id = %s', 319 (pickled_data, expiration_time, self.id)) 320 321 def _delete(self): 306 322 self.cursor.execute('delete from session where id=%s', (self.id,)) 307 pickled_data = pickle.dumps(self._data) 308 self.cursor.execute( 309 'insert into session (id, data, expiration_time) values (%s, %s, %s)', 310 (self.id, pickled_data, expiration_time)) 311 323 312 324 def acquire_lock(self): 313 325 # We use the "for update" clause to lock the row 326 self.locked = True 314 327 self.cursor.execute('select id from session where id=%s for update', 315 328 (self.id,)) … … 319 332 # introduced by the "for update" clause 320 333 self.cursor.close() 334 self.locked = False 321 335 322 336 def clean_up(self): … … 403 417 cookie[name]['secure'] = 1 404 418 419 def expire(): 420 """Expire the current session cookie.""" 421 name = cherrypy.request.config.get('tools.sessions.name', 'session_id') 422 one_year = 60 * 60 * 24 * 365 423 exp = time.gmtime(time.time() - one_year) 424 t = time.strftime("%a, %d-%b-%Y %H:%M:%S GMT", exp) 425 cherrypy.response.simple_cookie[name]['expires'] = t 426 trunk/cherrypy/test/test_session.py
r1275 r1287 9 9 10 10 import cherrypy 11 from cherrypy.lib import sessions 11 12 12 13 … … 44 45 return str(c) 45 46 index.exposed = True 47 48 def delete(self): 49 cherrypy.session.delete() 50 sessions.expire() 51 return "done" 52 delete.exposed = True 46 53 47 54 cherrypy.tree.mount(Root()) … … 59 66 self.getPage('/testStr', self.cookies) 60 67 self.assertBody('3') 68 61 69 self.getPage('/setsessiontype/file') 62 70 self.getPage('/testStr') … … 72 80 self.assertBody('1') 73 81 74 # Wait for the cleanup thread to delete session files 82 # Test session delete 83 self.getPage('/delete', self.cookies) 84 self.assertBody("done") 85 f = lambda: [x for x in os.listdir(localDir) if x.startswith('session-')] 86 self.assertEqual(f(), []) 87 88 # Wait for the cleanup thread to delete remaining session files 89 self.getPage('/') 75 90 f = lambda: [x for x in os.listdir(localDir) if x.startswith('session-')] 76 91 self.assertNotEqual(f(), [])

