Changeset 420
- Timestamp:
- 07/06/05 22:25:50
- Files:
-
- trunk/cherrypy/lib/filter/sessionfilter/__init__.py (modified) (7 diffs)
- trunk/cherrypy/lib/filter/sessionfilter/anydbadaptor.py (modified) (1 diff)
- trunk/cherrypy/lib/filter/sessionfilter/basesession.py (modified) (4 diffs)
- trunk/cherrypy/lib/filter/sessionfilter/fileadaptor.py (modified) (3 diffs)
- trunk/cherrypy/lib/filter/sessionfilter/sessionconfig.py (modified) (1 diff)
- trunk/cherrypy/tutorial/tutorial.conf (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/cherrypy/lib/filter/sessionfilter/__init__.py
r417 r420 23 23 pass 24 24 25 try: 26 from threading import local 27 except ImportError: 28 from cherrypy._cpthreadinglocal import local 29 25 30 26 31 class SessionFilter: … … 32 37 """ Initilizes the session filter and creates cherrypy.sessions """ 33 38 34 try:35 from threading import local36 except ImportError:37 from cherrypy._cpthreadinglocal import local38 39 39 # Create as sessions object for accessing session data 40 40 cherrypy.sessions = local() … … 87 87 configMap = cherrypy.config.configMap 88 88 89 self.__localData.config= {}89 configData = {} 90 90 self.__localData.activeSessions = [] 91 91 92 92 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 93 98 if path == '/': 94 99 section = 'global' 95 100 else: 96 101 section = path 97 102 103 # will will place all of the config data here as we read it 98 104 sectionData = {} 99 105 106 # get the current settings or return an empty dictionary 100 107 settings = cherrypy.config.configMap.get(section, {}) 101 #print section, settings 108 109 # iterate over all of the settings for the current path 102 110 for key, value in settings.iteritems(): 111 # make sure this is a session setting 103 112 if key.startswith('sessionFilter.'): 104 sectionData = self.__localData.config.setdefault(section, {})113 sectionData = configData.setdefault(section, {}) 105 114 keySplit = key.split('.') 115 116 # if the key has 1 '.' then it is a default setting 106 117 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 110 128 elif len(keySplit) == 3: 111 129 currentSession = sectionData.setdefault(keySplit[1], {}) 112 130 currentSession[keySplit[2]] = value 113 131 132 # we now iterate back over the settings and 133 # locate/initilize the session manager 114 134 for session, settings in sectionData.iteritems(): 115 135 if not settings['on']: … … 121 141 self.sessionManagers[session] = sessionManager 122 142 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 123 155 self.__localData.activeSessions.append(sessionManager) 124 156 125 157 def __initSessions(self): 126 158 … … 169 201 # if we do not have a manually defined cookie path use path where the session 170 202 # 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 173 209 174 210 cherrypy.response.simpleCookie[cookieName] = sessionKey … … 176 212 cherrypy.response.simpleCookie[cookieName]['max-age'] = timeout*60 177 213 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 178 228 def __saveSessions(self): 179 229 … … 189 239 if sessionManager.nextCleanUp < now: 190 240 sessionManager.cleanUpOldSessions() 191 cleanUpDelay = session config.retrieve('cleanUpDelay', sessionManager.name)241 cleanUpDelay = sessionManager.settings.cleanUpDelay 192 242 sessionManager.nextCleanUp=now + cleanUpDelay * 60 193 243 trunk/cherrypy/lib/filter/sessionfilter/anydbadaptor.py
r400 r420 51 51 if not dbFile: 52 52 defaultFile = '%s.db' % sessionName 53 53 54 storagePath = sessionconfig.retrieve('storagePath', sessionName) 55 54 56 dbFile = os.path.join(storagePath, defaultFile) 55 57 self.__data = shelve.open(dbFile, 'c') trunk/cherrypy/lib/filter/sessionfilter/basesession.py
r412 r420 67 67 def generateSessionKey(self): 68 68 """ 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 70 73 71 74 if sessionKeyFunc: … … 102 105 103 106 # settings dict 104 self.settings = local()107 self.settings = None 105 108 106 109 … … 145 148 self.setSession(session) 146 149 147 cacheTimeout = se ssionconfig.retrieve('cacheTimeout', self.name, None)150 cacheTimeout = self.settings.cacheTimeout 148 151 149 152 if session.threadCount == 0 and (self.noCache or not cacheTimeout): … … 158 161 """ cleanup all inactive sessions """ 159 162 160 cacheTimeout = sessionconfig.retrieve('cacheTimeout', self.name, None) 163 cacheTimeout = self.settings.cacheTimeout 164 161 165 # don't waste cycles if we aren't caching inactive sessions 162 166 if cacheTimeout and not self.noCache: trunk/cherrypy/lib/filter/sessionfilter/fileadaptor.py
r400 r420 56 56 raise SessionNotFoundError 57 57 58 storageDir = sessionconfig.retrieve('storagePath', self.name) 58 storageDir = self.settings.storagePath 59 59 60 fileName = '%s-%s' % (self.name, sessionKey) 60 61 filePath = os.path.join(storageDir, fileName) … … 72 73 def setSession(self, sessionData): 73 74 74 storageDir = sessionconfig.retrieve('storagePath', self.name) 75 storageDir = self.settings.storagePath 76 75 77 fileName = '%s-%s' % (self.name, sessionData.key) 76 78 filePath = os.path.join(storageDir, fileName) … … 83 85 84 86 def delSession(self, sessionKey): 85 storageDir = se ssionconfig.retrieve('storagePath', self.name)87 storageDir = self.settings.storagePath 86 88 fileName = '%s-%s' % (self.name, sessionKey) 87 89 filePath = os.path.join(storageDir, fileName) trunk/cherrypy/lib/filter/sessionfilter/sessionconfig.py
r417 r420 43 43 'sessionFilter.cookiePrefix': 'CherryPySession', 44 44 'sessionFilter.storagePath': '.sessiondata', 45 'sessionFilter.default.on': True 45 'sessionFilter.default.on': True, 46 'sessionFilter.cacheTimeout' : 0 46 47 } 47 48 trunk/cherrypy/tutorial/tutorial.conf
r392 r420 3 3 server.threadPool = 10 4 4 server.environment = "production" 5 sessionFilter.default.storageType= "ram"6 5 # server.logToScreen = False

