Download Install Tutorial Docs FAQ Tools WikiLicense Team IRC Planet Involvement Shop Book

Changeset 1583

Show
Ignore:
Timestamp:
12/29/06 06:03:26
Author:
lawouach
Message:

Backport to 2.2 of #525

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/cherrypy-2.x/cherrypy/filters/sessionfilter.py

    r1578 r1583  
    9393        clean_up_delay = conf('session_filter.clean_up_delay', 5) 
    9494        clean_up_delay = datetime.timedelta(seconds = clean_up_delay * 60) 
    95          
     95 
    9696        cookie_name = conf('session_filter.cookie_name', 'session_id') 
    9797        cookie_domain = conf('session_filter.cookie_domain', None) 
     
    227227    def save(self, id, data, expiration_time): 
    228228        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 
    230235    def acquire_lock(self): 
    231236        sess = cherrypy.request._session 
     
    289294        f.close() 
    290295     
     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         
    291305    def acquire_lock(self): 
    292306        sess = cherrypy.request._session 
     
    322336                        # Session expired: deleting it 
    323337                        id = fname[len(self.SESSION_PREFIX):] 
     338                        print file_path 
    324339                        sess.on_delete_session(data) 
    325340                        os.unlink(file_path) 
     
    386401        data = pickle.loads(pickled_data) 
    387402        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,))  
    388408     
    389409    def save(self, id, data, expiration_time): 
     
    458478        elif name == 'id': 
    459479            return sess.session_id 
     480        elif name == 'delete': 
     481            return sess.session_storage.delete 
    460482 
    461483        if sess.to_be_loaded: 
     
    474496        return getattr(sess.session_data, name) 
    475497 
     498def 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  
    22test.prefer_parent_path() 
    33 
    4 import cherrypy, os 
     4import cherrypy, os, time 
     5from cherrypy.filters import sessionfilter 
    56 
     7localDir = os.path.dirname(__file__) 
    68 
    79def setup_server(): 
     
    2224            cherrypy.config.update({'session_filter.storage_type': newtype}) 
    2325        setsessiontype.exposed = True 
     26 
     27        def delete(self): 
     28            cherrypy.session.delete()  
     29            sessionfilter.expire()  
     30            return "done"  
     31        delete.exposed = True 
    2432         
    2533    cherrypy.root = Root() 
     
    2937            'session_filter.on': True, 
    3038            '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, 
    3242    }) 
    3343 
     
    4353        self.getPage('/testStr', self.cookies) 
    4454        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         
    4562        self.getPage('/setsessiontype/file') 
    4663        self.getPage('/testStr') 
     
    5168        self.assertBody('3') 
    5269 
     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 
    5383        # Clean up session files 
    54         for fname in os.listdir('.'): 
     84        for fname in os.listdir(localDir): 
    5585            if fname.startswith('session-'): 
    56                 os.unlink(fname
     86                os.unlink(os.path.join(localDir, fname)
    5787 
    5888if __name__ == "__main__": 

Hosted by WebFaction

Log in as guest/cpguest to create tickets