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

Changeset 984

Show
Ignore:
Timestamp:
02/28/06 10:05:09
Author:
rdelon
Message:

Added "on_renew_session" callback to sessionfilter

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/cherrypy/filters/sessionfilter.py

    r983 r984  
    8282        sess.session_locking = conf('session_filter.locking', 'explicit') 
    8383        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', 
    8486                lambda data: None) 
    8587        sess.on_delete_session = conf('session_filter.on_delete_session', 
     
    264266     
    265267    def load(self, id): 
    266         filePath = self._getFilePath(id) 
     268        file_path = self._get_file_path(id) 
    267269        try: 
    268             f = open(filePath, "rb") 
     270            f = open(file_path, "rb") 
    269271            data = pickle.load(f) 
    270272            f.close() 
     
    274276     
    275277    def save(self, id, data, expiration_time): 
    276         filePath = self._getFilePath(id) 
    277         f = open(filePath, "wb") 
     278        file_path = self._get_file_path(id) 
     279        f = open(file_path, "wb") 
    278280        pickle.dump((data, expiration_time), f) 
    279281        f.close() 
     
    281283    def acquire_lock(self): 
    282284        sess = cherrypy.request._session 
    283         filePath = self._getFilePath(cherrypy.session.id) 
    284         lockFilePath = filePath + self.LOCK_SUFFIX 
    285         self._lockFile(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) 
    286288        sess.locked = True 
    287289     
    288290    def release_lock(self): 
    289291        sess = cherrypy.request._session 
    290         filePath = self._getFilePath(cherrypy.session.id) 
    291         lockFilePath = filePath + self.LOCK_SUFFIX 
    292         self._unlockFile(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) 
    293295        sess.locked = False 
    294296     
     
    303305                # We have a session file: try to load it and check 
    304306                #   if it's expired. If it fails, nevermind. 
    305                 filePath = os.path.join(storage_path, fname) 
     307                file_path = os.path.join(storage_path, fname) 
    306308                try: 
    307                     f = open(filePath, "rb") 
     309                    f = open(file_path, "rb") 
    308310                    data, expiration_time = pickle.load(f) 
    309311                    f.close() 
     
    312314                        id = fname[len(self.SESSION_PREFIX):] 
    313315                        sess.on_delete_session(data) 
    314                         os.unlink(filePath) 
     316                        os.unlink(file_path) 
    315317                except: 
    316318                    # We can't access the file ... nevermind 
    317319                    pass 
    318320     
    319     def _getFilePath(self, id): 
     321    def _get_file_path(self, id): 
    320322        storage_path = cherrypy.config.get('session_filter.storage_path') 
    321323        if storage_path is None: 
    322324            raise SessionStoragePathNotConfiguredError() 
    323325        fileName = self.SESSION_PREFIX + id 
    324         filePath = os.path.join(storage_path, fileName) 
    325         return filePath 
    326      
    327     def _lockFile(self, path): 
     326        file_path = os.path.join(storage_path, fileName) 
     327        return file_path 
     328     
     329    def _lock_file(self, path): 
    328330        sess = cherrypy.request._session 
    329331        startTime = time.time() 
     
    339341                break 
    340342     
    341     def _unlockFile(self, path): 
     343    def _unlock_file(self, path): 
    342344        os.unlink(path) 
    343345 
     
    446448                # flush session data (but keep the same session_id) 
    447449                sess.session_data = {'_id': sess.session_id} 
     450                if not (data is None): 
     451                    sess.on_renew_session(sess.session_data) 
    448452            else: 
    449453                sess.session_data = data[0] 
  • trunk/docs/book/xml/sessions.xml

    r944 r984  
    8787      </listitem> 
    8888      <listitem> 
     89        <para><option>session_filter.on_renew_session</option>: See <xref 
     90        linkend="callbacks" />.</para> 
     91      </listitem> 
     92      <listitem> 
    8993        <para><option>session_filter.on_delete_session</option>: See <xref 
    9094        linkend="callbacks" />.</para> 
     
    198202    <para>It is possible to configure the <literal>session_filter</literal> so 
    199203    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 
    202207    <literal>session_filter.on_delete_session</literal> config options. When a 
    203208    session is created/deleted, CherryPy will call these functions and pass 

Hosted by WebFaction

Log in as guest/cpguest to create tickets