Changeset 1583
- Timestamp:
- 12/29/06 06:03:26
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/cherrypy-2.x/cherrypy/filters/sessionfilter.py
r1578 r1583 93 93 clean_up_delay = conf('session_filter.clean_up_delay', 5) 94 94 clean_up_delay = datetime.timedelta(seconds = clean_up_delay * 60) 95 95 96 96 cookie_name = conf('session_filter.cookie_name', 'session_id') 97 97 cookie_domain = conf('session_filter.cookie_domain', None) … … 227 227 def save(self, id, data, expiration_time): 228 228 cherrypy._session_data_holder[id] = (data, expiration_time) 229 229 230 def delete(self, id=None): 231 if id is None: 232 id = cherrypy.session.id 233 del cherrypy._session_data_holder[id] 234 230 235 def acquire_lock(self): 231 236 sess = cherrypy.request._session … … 289 294 f.close() 290 295 296 def delete(self, id=None): 297 if id is None: 298 id = cherrypy.session.id 299 file_path = self._get_file_path(id) 300 try: 301 os.unlink(file_path) 302 except: 303 pass 304 291 305 def acquire_lock(self): 292 306 sess = cherrypy.request._session … … 322 336 # Session expired: deleting it 323 337 id = fname[len(self.SESSION_PREFIX):] 338 print file_path 324 339 sess.on_delete_session(data) 325 340 os.unlink(file_path) … … 386 401 data = pickle.loads(pickled_data) 387 402 return (data, expiration_time) 403 404 def delete(self, id=None): 405 if id is None: 406 id = cherrypy.session.id 407 self.cursor.execute('delete from session where id=%s', (id,)) 388 408 389 409 def save(self, id, data, expiration_time): … … 458 478 elif name == 'id': 459 479 return sess.session_id 480 elif name == 'delete': 481 return sess.session_storage.delete 460 482 461 483 if sess.to_be_loaded: … … 474 496 return getattr(sess.session_data, name) 475 497 498 def expire(): 499 """Expire the current session cookie.""" 500 name = cherrypy.config.get('session_filter.cookie_name', 'session_id') 501 one_year = 60 * 60 * 24 * 365 502 exp = time.gmtime(time.time() - one_year) 503 t = time.strftime("%a, %d-%b-%Y %H:%M:%S GMT", exp) 504 cherrypy.response.simple_cookie[name]['expires'] = t branches/cherrypy-2.x/cherrypy/test/test_session_filter.py
r1017 r1583 2 2 test.prefer_parent_path() 3 3 4 import cherrypy, os 4 import cherrypy, os, time 5 from cherrypy.filters import sessionfilter 5 6 7 localDir = os.path.dirname(__file__) 6 8 7 9 def setup_server(): … … 22 24 cherrypy.config.update({'session_filter.storage_type': newtype}) 23 25 setsessiontype.exposed = True 26 27 def delete(self): 28 cherrypy.session.delete() 29 sessionfilter.expire() 30 return "done" 31 delete.exposed = True 24 32 25 33 cherrypy.root = Root() … … 29 37 'session_filter.on': True, 30 38 'session_filter.storage_type' : 'file', 31 'session_filter.storage_path' : '.', 39 'session_filter.storage_path' : localDir, 40 'session_filter.timeout': 0.017, 41 'session_filter.clean_up_delay': 0.017, 32 42 }) 33 43 … … 43 53 self.getPage('/testStr', self.cookies) 44 54 self.assertBody('3') 55 56 self.getPage('/delete', self.cookies) 57 self.assertBody("done") 58 59 f = lambda: [x for x in os.listdir(localDir) if x.startswith('session-')] 60 self.assertEqual(f(), []) 61 45 62 self.getPage('/setsessiontype/file') 46 63 self.getPage('/testStr') … … 51 68 self.assertBody('3') 52 69 70 f = lambda: [x for x in os.listdir(localDir) if x.startswith('session-')] 71 self.assertNotEqual(f(), []) 72 73 self.getPage('/delete', self.cookies) 74 self.assertBody("done") 75 76 f = lambda: [x for x in os.listdir(localDir) if x.startswith('session-')] 77 self.assertEqual(f(), []) 78 79 self.getPage('/testStr') 80 f = lambda: [x for x in os.listdir(localDir) if x.startswith('session-')] 81 self.assertNotEqual(f(), []) 82 53 83 # Clean up session files 54 for fname in os.listdir( '.'):84 for fname in os.listdir(localDir): 55 85 if fname.startswith('session-'): 56 os.unlink( fname)86 os.unlink(os.path.join(localDir, fname)) 57 87 58 88 if __name__ == "__main__":

