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

Changeset 420

Show
Ignore:
Timestamp:
07/06/05 22:25:50
Author:
mikerobi
Message:

sessionfilter configuration improvements, once the last remaing calls to sessionconfig.retrieve are removed everything should be ready for a release.

Files:

Legend:

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

    r417 r420  
    2323    pass 
    2424 
     25try: 
     26    from threading import local 
     27except ImportError: 
     28    from cherrypy._cpthreadinglocal import local 
     29 
    2530 
    2631class SessionFilter: 
     
    3237        """ Initilizes the session filter and creates cherrypy.sessions  """ 
    3338 
    34         try: 
    35             from threading import local 
    36         except ImportError: 
    37             from cherrypy._cpthreadinglocal import local 
    38          
    3939        # Create as sessions object for accessing session data 
    4040        cherrypy.sessions = local() 
     
    8787        configMap = cherrypy.config.configMap 
    8888         
    89         self.__localData.config = {} 
     89        configData = {} 
    9090        self.__localData.activeSessions = [] 
    9191         
    9292        for path in self.__pathList(): 
     93            # cut index off the end of the pass 
     94            if path.endswith('/index'): 
     95                path = path[0:-5] 
     96             
     97            # set the section  
    9398            if path == '/': 
    9499                section = 'global' 
    95100            else: 
    96101                section = path 
    97                  
     102             
     103            # will will place all of the config data here as we read it 
    98104            sectionData = {} 
    99105             
     106            # get the current settings or return an empty dictionary 
    100107            settings = cherrypy.config.configMap.get(section, {}) 
    101             #print section, settings 
     108             
     109            # iterate over all of the settings for the current path 
    102110            for key, value in settings.iteritems(): 
     111                # make sure this is a session setting 
    103112                if key.startswith('sessionFilter.'): 
    104                     sectionData = self.__localData.config.setdefault(section, {}) 
     113                    sectionData = configData.setdefault(section, {}) 
    105114                    keySplit = key.split('.') 
     115                     
     116                    # if the key has 1 '.' then it is a default setting 
    106117                    if len(keySplit) == 2: 
    107                         defaults = self.__localData.config.setdefault(None, {}) 
    108                         #defaults[keySplit[1]] = value 
    109                         #defaults = sectionData.setdefault(None, {}) 
     118                        # we use None as the key for default settings 
     119                        # and we place the key, value in the dictionary 
     120 
     121                        # because we iterate from / down to the current node 
     122                        # we will automatically overwite any default values 
     123                        # if they are redefined by child nodes 
     124                        defaults = configData.setdefault(None, {}) 
     125                        defaults[keySplit[1]] = value 
     126                     
     127                    # if the key has 3 '.' then it is a named session 
    110128                    elif len(keySplit) == 3: 
    111129                        currentSession = sectionData.setdefault(keySplit[1], {}) 
    112130                        currentSession[keySplit[2]] = value 
    113131             
     132            # we now iterate back over the settings and 
     133            # locate/initilize the session manager 
    114134            for session, settings in sectionData.iteritems(): 
    115135                if not settings['on']: 
     
    121141                    self.sessionManagers[session] = sessionManager 
    122142                 
     143                # create a new local instance 
     144                setattr(sessionManager, 'settings', local()) 
     145                 
     146                # set all of the default settings 
     147                for key, value in configData.get(None, {}).iteritems(): 
     148                    setattr(sessionManager.settings, key, value) 
     149                 
     150                # set all of settings 
     151                for key, value in settings.iteritems(): 
     152                    setattr(sessionManager.settings, key, value) 
     153 
     154                # add this to the list of active session managers 
    123155                self.__localData.activeSessions.append(sessionManager) 
    124              
     156     
    125157    def __initSessions(self): 
    126158         
     
    169201        # if we do not have a manually defined cookie path use path where the session 
    170202        # manager was defined 
    171         cookiePath = sessionconfig.retrieve('cookiePath', sessionManager.name, sessionManager.path) 
    172         timeout = sessionconfig.retrieve('timeout', sessionManager.name) 
     203        try: 
     204            cookiePath = self.settings.cookiePath 
     205        except AttributeError: 
     206            cookiePath = sessionManager.path 
     207 
     208        timeout = sessionManager.settings.timeout 
    173209         
    174210        cherrypy.response.simpleCookie[cookieName] = sessionKey 
     
    176212        cherrypy.response.simpleCookie[cookieName]['max-age'] = timeout*60 
    177213         
     214        # try and set the cookie domain 
     215        try: 
     216            cookieDomain = self.settings.cookieDomain 
     217            cherrypy.response.simpleCookie[cookieName]['domain'] = cookieDomain 
     218        except AttributeError: 
     219            pass 
     220 
     221        # try and set a cookie comment 
     222        try: 
     223            cookieComment = self.settings.cookieComment 
     224            cherrypy.response.simpleCookie[cookieName]['comment'] = cookieComment 
     225        except AttributeError: 
     226            pass 
     227 
    178228    def __saveSessions(self): 
    179229         
     
    189239            if sessionManager.nextCleanUp < now: 
    190240                sessionManager.cleanUpOldSessions() 
    191                 cleanUpDelay = sessionconfig.retrieve('cleanUpDelay', sessionManager.name) 
     241                cleanUpDelay = sessionManager.settings.cleanUpDelay 
    192242                sessionManager.nextCleanUp=now + cleanUpDelay * 60 
    193243 
  • trunk/cherrypy/lib/filter/sessionfilter/anydbadaptor.py

    r400 r420  
    5151        if not dbFile: 
    5252            defaultFile = '%s.db' % sessionName 
     53             
    5354            storagePath = sessionconfig.retrieve('storagePath', sessionName) 
     55             
    5456            dbFile = os.path.join(storagePath, defaultFile) 
    5557        self.__data = shelve.open(dbFile, 'c') 
  • trunk/cherrypy/lib/filter/sessionfilter/basesession.py

    r412 r420  
    6767    def generateSessionKey(self): 
    6868        """ Function to return a new sessioId """ 
    69         sessionKeyFunc = sessionconfig.retrieve('keyGenerator', self.name, None) 
     69        try: 
     70            sessionKeyFunc = self.settings.keyGenerator 
     71        except AttributeError: 
     72            sessionKeyFunc = None 
    7073         
    7174        if sessionKeyFunc: 
     
    102105 
    103106        # settings dict 
    104         self.settings = local() 
     107        self.settings = None 
    105108            
    106109     
     
    145148            self.setSession(session) 
    146149         
    147             cacheTimeout = sessionconfig.retrieve('cacheTimeout',  self.name, None) 
     150            cacheTimeout = self.settings.cacheTimeout 
    148151             
    149152            if session.threadCount == 0 and (self.noCache or not cacheTimeout): 
     
    158161        """ cleanup all inactive sessions """ 
    159162         
    160         cacheTimeout = sessionconfig.retrieve('cacheTimeout',  self.name, None) 
     163        cacheTimeout = self.settings.cacheTimeout 
     164         
    161165        # don't waste cycles if we aren't caching inactive sessions 
    162166        if cacheTimeout and not self.noCache: 
  • trunk/cherrypy/lib/filter/sessionfilter/fileadaptor.py

    r400 r420  
    5656            raise SessionNotFoundError 
    5757         
    58         storageDir = sessionconfig.retrieve('storagePath', self.name) 
     58        storageDir = self.settings.storagePath 
     59 
    5960        fileName = '%s-%s' % (self.name, sessionKey) 
    6061        filePath = os.path.join(storageDir, fileName) 
     
    7273    def setSession(self, sessionData): 
    7374     
    74         storageDir = sessionconfig.retrieve('storagePath', self.name)    
     75        storageDir = self.settings.storagePath 
     76 
    7577        fileName = '%s-%s' % (self.name, sessionData.key) 
    7678        filePath = os.path.join(storageDir, fileName) 
     
    8385 
    8486    def delSession(self, sessionKey): 
    85         storageDir = sessionconfig.retrieve('storagePath', self.name)   
     87        storageDir = self.settings.storagePath 
    8688        fileName = '%s-%s' % (self.name, sessionKey) 
    8789        filePath = os.path.join(storageDir, fileName) 
  • trunk/cherrypy/lib/filter/sessionfilter/sessionconfig.py

    r417 r420  
    4343    'sessionFilter.cookiePrefix': 'CherryPySession', 
    4444    'sessionFilter.storagePath': '.sessiondata', 
    45     'sessionFilter.default.on': True 
     45    'sessionFilter.default.on': True, 
     46    'sessionFilter.cacheTimeout' : 0 
    4647} 
    4748 
  • trunk/cherrypy/tutorial/tutorial.conf

    r392 r420  
    33server.threadPool = 10 
    44server.environment = "production" 
    5 sessionFilter.default.storageType= "ram" 
    65# server.logToScreen = False 

Hosted by WebFaction

Log in as guest/cpguest to create tickets