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

Changeset 444

Show
Ignore:
Timestamp:
07/10/05 22:11:57
Author:
mikerobi
Message:

sessionFilter: fixed expired() bug. Finished implementing the session filter configuration changes. cherrypy.session is an alias for cherrypy.session.default, so you can use cherrypy.session[key], or cherrypy.session.default[key], but the session attributes (sessionKey, timeout, ...) can only be accessed through cherrypy.session.default

Files:

Legend:

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

    r418 r444  
    5757response = local() 
    5858 
     59from cherrypy.lib.filter.sessionfilter.localdict import LocalDict 
     60# create session object 
     61session = LocalDict() 
     62 
    5963# Create threadData object as a thread-specific all-purpose storage 
    6064threadData = local() 
  • trunk/cherrypy/lib/filter/sessionfilter/__init__.py

    r426 r444  
    77    'sessionFilter.sessionList' : ['default'], 
    88    'sessionFilter.storageAdaptors' : {}, 
    9     'sessionFilter.default.on': True, 
    10  
    119    'sessionFilter.timeout': 60, 
    1210    'sessionFilter.cleanUpDelay': 60, 
     
    5149        """ Initilizes the session filter and creates cherrypy.sessions  """ 
    5250 
    53         # Create as sessions object for accessing session data 
    54         cherrypy.sessions = local() 
    55          
    5651        self.__localData= local() 
    5752         
     
    247242            sessionName = sessionManager.name 
    248243             
    249             sessionData = getattr(cherrypy.sessions, sessionName) 
     244            sessionData = getattr(cherrypy.session, sessionName) 
    250245            sessionManager.commitCache(sessionData.key) 
    251246            sessionManager.cleanUpCache() 
  • trunk/cherrypy/lib/filter/sessionfilter/baseadaptor.py

    r423 r444  
    144144     
    145145        session.cookieName = self.cookieName 
    146         setattr(cherrypy.sessions, self.name, session) 
     146        setattr(cherrypy.session, self.name, session) 
    147147     
    148148    def createSession(self): 
  • trunk/cherrypy/lib/filter/sessionfilter/basesessiondict.py

    r382 r444  
    3131 
    3232 
    33 def locker(function): 
    34     def _inner(self, *args, **kwds): 
    35         self._lock.acquire() 
    36         result = function(self, *args, **kwds) 
    37         self._lock.release() 
    38         return result 
    39     return _inner 
    40  
    4133# this is a dictionary like class that will be exposed to the application 
    4234# this class is used by  
     
    6658         
    6759    def get(self, key, default = None): 
    68         try: 
    69             return self.__getitem__(key) 
    70         except KeyError: 
    71             return default 
     60        pass 
    7261         
    7362    def __getitem__(self, key): 
     
    8170     
    8271    def __setattr__(self, attr, value): 
    83         pass  
     72        pass 
     73 
     74    def setdefault(self, key, default): 
     75        pass 
     76 
     77    # needed for conversion to a dict 
     78    def __iter__(self): 
     79        pass 
    8480     
    8581    def expired(self): 
    8682        now = time.time() 
    87         return (now - self.lastAccess) < self.timeout 
     83         
     84        return (now - self.lastAccess) > self.timeout 
    8885     
    8986    # additional functions 
  • trunk/cherrypy/lib/filter/sessionfilter/simplesessiondict.py

    r283 r444  
    6767        self.__sessionData[key] = value 
    6868    __setitem__=locker(__setitem__) 
    69          
     69       
     70    def setdefault(self, key, default): 
     71        try: 
     72            return self.__sessionData[key] 
     73        except KeyError: 
     74            self.__sessionData[key] = default 
     75            return default 
     76    setdefault=locker(setdefault) 
     77 
    7078    def __getattr__(self, attr): 
    7179        try: 
     
    9199        self._lock.release() 
    92100     
     101    def __iter__(self): 
     102        return iter(self.__sessionData.copy()) 
     103         
    93104    def __getstate__(self): 
    94105        """ remove the lock so we can pickle """ 
  • trunk/cherrypy/test/test_session_filter.py

    r443 r444  
    4848                    'sessionFilter.on' : True, 
    4949                    'sessionFilter.cacheTimeout' : 60, 
    50                     'sessionFilter.storagePath' : tmpFolder 
     50                    'sessionFilter.storagePath' : tmpFolder, 
     51                    'sessionFilter.default.on' : True 
    5152                    }, 
    5253               '/ram'   : { 'sessionFilter.ram.on'   : True, 'sessionFilter.ram.storageType'   : 'ram'   }, 
     
    6061     
    6162    def __go(self, storageType): 
    62         session = getattr(cherrypy.sessions, storageType) 
    63         count = session.get('count', 0) + 1 
    64         session['count'] = count 
     63        session = getattr(cherrypy.session, storageType) 
     64        count = session.setdefault('count', 1) 
     65        session['count'] = count + 1 
    6566        return str(count) 
    6667 
     68    def index(self): 
     69        count = cherrypy.session.setdefault('count', 1) 
     70        cherrypy.session['count'] = count + 1 
     71        return str(count) 
     72    index.exposed = True 
    6773 
    6874    def ram(self): 
     
    7379        return self.__go('file') 
    7480    file.exposed = True 
    75  
     81     
    7682    def anydb(self): 
    7783        return self.__go('anydb') 
    7884    anydb.exposed = True 
    79  
    8085 
    8186import threading 
     
    8489cherrypy.config.update(server_conf.copy()) 
    8590 
    86 def reloadCP(): 
    87     reload(cherrypy) 
    88     cherrypy.config.update(server_conf.copy()) 
    89     cherrypy.server.start(initOnly = True) 
    90  
    9191class SessionFilterTest(unittest.TestCase): 
    9292 
    93     def __testStorageType(self, storageType, startCount = 1, iterations = 5, persistant=False): 
     93    def __testSession(self, requestPath, iterations = 5, persistant=False): 
    9494        #cherrypy.config.update({"sessionFilter.storageType": storageType}) 
    9595         
    96         helper.request('/' + storageType
    97         self.assertEqual(cherrypy.response.body, str(startCount)
     96        helper.request(requestPath
     97        self.assertEqual(cherrypy.response.body, '1'
    9898         
    9999        cookie = dict(cherrypy.response.headers)['Set-Cookie'] 
    100100         
    101101        # this loop will be used to test thread safety 
    102         for n in xrange(startCount+1, startCount + iterations + 1): 
     102        for n in xrange(2, 3 + iterations): 
    103103            if persistant: 
    104104                cherrypy.server.stop() 
    105105                cherrypy.server.start(initOnly = True) 
    106             helper.request('/' + storageType, [('Cookie', cookie)]) 
     106            helper.request(requestPath, [('Cookie', cookie)]) 
    107107            self.assertEqual(cherrypy.response.body, str(n)) 
    108108 
     
    113113        pass 
    114114     
     115    def testDefaultSession(self): 
     116        self.__testSession('/', persistant=False) 
     117         
    115118    def testRamSessions(self): 
    116         self.__testStorageType('ram', persistant=False) 
     119        self.__testSession('/ram', persistant=False) 
    117120     
    118121    def testFileSessions(self): 
    119         self.__testStorageType('file', persistant=True) 
     122        self.__testSession('/file', persistant=True) 
    120123     
    121124    def testAnydbSessions(self): 
    122         self.__testStorageType('anydb', persistant=True) 
     125        self.__testSession('/anydb', persistant=True) 
    123126    
    124     def __testThreadSafety(self, storageType = 'ram'): 
     127    def __testThreadSafety(self): 
    125128        for z in range(30): 
    126             threading.Thread(target = self.__testStorageType, args = ('ram', 1, 4)).start() 
     129            threading.Thread(target = self.__testSession, args = ('/ram')).start() 
    127130 
    128131    ''' 
    129132    def testSqlObjectSession(self): 
    130         self.__testStorageType('sqlobject') 
     133        self.__testSession('sqlobject') 
    131134    ''' 
    132135 
  • trunk/cherrypy/tutorial/tut07_sessions.py

    r382 r444  
    1515    def index(self): 
    1616        # Increase the silly hit counter 
    17         count = cherrypy.sessions.default.get('count', 0) + 1 
     17        count = cherrypy.session.get('count', 0) + 1 
    1818         
    1919        # Store the new value in the session dictionary 
    20         cherrypy.sessions.default['count'] = count 
     20        cherrypy.session['count'] = count 
    2121         
    2222        # And display a silly hit count message! 
  • trunk/cherrypy/tutorial/tut08_advanced_sessions.py

    r431 r444  
    4040         
    4141        # Increase the silly hit counter 
    42         count = cherrypy.sessions.default.get('count', 0) + 1 
     42        count = cherrypy.session.get('count', 0) + 1 
    4343 
    4444        # Store the new value in the session dictionary 
    45         # cherrypy.sessions.default is available by default 
    46         cherrypy.sessions.default['count'] = count 
     45        # cherrypy.session is available by default 
     46        cherrypy.session['count'] = count 
    4747 
    4848        # And display a silly hit count message! 
    49         key = cherrypy.sessions.default.key 
    50         cookieName = cherrypy.sessions.default.cookieName 
     49        # cherrypy.session is an alias to cherrypy.session.default 
     50        # it allows dictionary functionality but the attributes 
     51        # must be accessed through cherrypy.session.default 
     52        key = cherrypy.session.default.key 
     53        cookieName = cherrypy.session.default.cookieName 
    5154        return self.__examplePage('ram', count, self.samplePages, key, cookieName) 
    5255 
     
    5861        # it mirrors the session function 
    5962 
    60         adminCount = cherrypy.sessions.admin.get('adminCount', 0) + 1 
    61         cherrypy.sessions.admin['adminCount'] = adminCount 
     63        adminCount = cherrypy.session.admin.get('adminCount', 0) + 1 
     64        cherrypy.session.admin['adminCount'] = adminCount 
    6265         
    63         key = cherrypy.sessions.admin.key 
    64         cookieName = cherrypy.sessions.admin.cookieName 
     66        key = cherrypy.session.admin.key 
     67        cookieName = cherrypy.session.admin.cookieName 
    6568        return self.__examplePage('ram', adminCount, self.samplePages, key, cookieName) 
    6669     
     
    7376        # it mirrors the session function 
    7477         
    75         forumCount = cherrypy.sessions.forum.get('forumCount', 0) + 1 
    76         cherrypy.sessions.forum['forumCount'] = forumCount 
     78        forumCount = cherrypy.session.forum.get('forumCount', 0) + 1 
     79        cherrypy.session.forum['forumCount'] = forumCount 
    7780         
    78         key = cherrypy.sessions.forum.key 
     81        key = cherrypy.session.forum.key 
    7982 
    80         cookieName = cherrypy.sessions.forum.cookieName 
     83        cookieName = cherrypy.session.forum.cookieName 
    8184        return self.__examplePage('ram', forumCount, self.samplePages, key, cookieName) 
    8285     
  • trunk/docs/book/build.sh

    r370 r444  
    5353        tar zxf docbook-xsl-1.68.1.tar.gz 
    5454    fi 
    55     cd $current 
     55    cd "$current" 
    5656} 
    5757 

Hosted by WebFaction

Log in as guest/cpguest to create tickets