Changeset 392
- Timestamp:
- 06/27/05 22:36:45
- Files:
-
- trunk/cherrypy/config.py (modified) (3 diffs)
- trunk/cherrypy/lib/filter/sessionfilter/__init__.py (modified) (9 diffs)
- trunk/cherrypy/lib/filter/sessionfilter/anydbadaptor.py (moved) (moved from trunk/cherrypy/lib/filter/sessionfilter/dbmsession.py)
- trunk/cherrypy/lib/filter/sessionfilter/fileadaptor.py (moved) (moved from trunk/cherrypy/lib/filter/sessionfilter/filesession.py)
- trunk/cherrypy/lib/filter/sessionfilter/ramadaptor.py (moved) (moved from trunk/cherrypy/lib/filter/sessionfilter/ramsession.py)
- trunk/cherrypy/lib/filter/sessionfilter/sessionerrors.py (modified) (1 diff)
- trunk/cherrypy/lib/filter/sessionfilter/sqlobjectadaptor.py (added)
- trunk/cherrypy/lib/filter/sessionfilter/sqlobjectsession.py (deleted)
- trunk/cherrypy/tutorial/tut09_sessionfilter.py (modified) (1 diff)
- trunk/cherrypy/tutorial/tutorial.conf (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/cherrypy/config.py
r382 r392 90 90 _load(file) 91 91 92 def get(key, defaultValue=None, returnSection=False , startPath = None):92 def get(key, defaultValue=None, returnSection=False): 93 93 # Look, ma, no Python function calls! Uber-fast. 94 # startPath lets you overload the starting search path (needed by getAll) 95 if startPath: 96 path = startPath 97 else: 98 try: 99 path = cherrypy.request.path 100 except AttributeError: 101 path = "/" 94 95 try: 96 path = cherrypy.request.path 97 except AttributeError: 98 path = "/" 102 99 103 100 while True: … … 135 132 This function is required by the session filter 136 133 """ 137 path = get(key, None, returnSection = True) 138 value = get(key) 139 140 result = {} 141 while value != None and path != '/': 142 result[path]= value 143 path = os.path.split(path)[0] 144 value = get(key, None, returnSection = False, startPath = path) 145 path = get(key, None, returnSection = True, startPath = path) 146 147 if path == '/' and value != None: 148 result[path] = value 149 150 return result 151 134 135 try: 136 path = cherrypy.request.path 137 except AttributeError: 138 path = "/" 139 140 pathList = cherrypy.request.path.split('/') 141 142 results = {} 143 144 try: 145 results = {'/' : configMap['global'][key]} 146 except KeyError: 147 pass 148 149 if path == '/': 150 return results 151 152 for n in xrange(1, len(pathList)): 153 path = '/'.join(pathList[0:n+1]) 154 try: 155 results[path] = configMap[path][key] 156 except KeyError: 157 pass 158 159 return results 160 152 161 153 162 class CaseSensitiveConfigParser(ConfigParser.ConfigParser): … … 197 206 def outputConfigMap(): 198 207 cherrypy.log("Server parameters:", 'CONFIG') 199 cherrypy.log(" server.environment: %s" % get('server.environment'), 'CONFIG')200 cherrypy.log(" server.logToScreen: %s" % get('server.logToScreen'), 'CONFIG')201 cherrypy.log(" server.logFile: %s" % get('server.logFile'), 'CONFIG')202 cherrypy.log(" server.protocolVersion: %s" % get('server.protocolVersion'), 'CONFIG')203 cherrypy.log(" server.socketHost: %s" % get('server.socketHost'), 'CONFIG')204 cherrypy.log(" server.socketPort: %s" % get('server.socketPort'), 'CONFIG')205 cherrypy.log(" server.socketFile: %s" % get('server.socketFile'), 'CONFIG')206 cherrypy.log(" server.reverseDNS: %s" % get('server.reverseDNS'), 'CONFIG')207 cherrypy.log(" server.socketQueueSize: %s" % get('server.socketQueueSize'), 'CONFIG')208 cherrypy.log(" server.threadPool: %s" % get('server.threadPool'), 'CONFIG')209 cherrypy.log(" session.storageType: %s" % get('session.storageType'), 'CONFIG')210 if get('session.storageType'):211 cherrypy.log(" session.timeout: %s min" % get('session.timeout'), 'CONFIG')212 cherrypy.log(" session.cleanUpDelay: %s min" % get('session.cleanUpDelay'), 'CONFIG') 213 cherrypy.log(" session.cookieName: %s" % get('session.cookieName'), 'CONFIG')214 cherrypy.log( " session.storageFileDir: %s" % get('session.storageFileDir'), 'CONFIG')215 cherrypy.log(" staticContent: %s" % get('staticContent'), 'CONFIG') 208 209 serverVars = [ 210 'server.environment', 211 'server.logToScreen', 212 'server.logFile', 213 'server.protocolVersion', 214 'server.socketHost', 215 'server.socketPort', 216 'server.socketFile', 217 'server.reverseDNS', 218 'server.socketQueueSize', 219 'server.threadPool' 220 ] 221 222 for var in serverVars: 223 cherrypy.log( " %s: %s" % (var, get(var)), 'CONFIG') 224 trunk/cherrypy/lib/filter/sessionfilter/__init__.py
r382 r392 4 4 5 5 import sessionconfig 6 from sessionerrors import SessionNotFoundError, SessionIncompatibleError 7 from ramsession import RamSession 8 from filesession import FileSession 9 from dbmsession import DBMSession 6 7 from sessionerrors import SessionNotFoundError, SessionIncompatibleError, SessionBadStorageTypeError 8 from ramadaptor import RamSession 9 from fileadaptor import FileSession 10 from anydbadaptor import DBMSession 10 11 11 12 _sessionTypes = { … … 23 24 24 25 25 def _getSessions3(): 26 sessions = {} 26 # this function gets all active sessions based on the path 27 def _getSessions(): 28 sessions = [] 27 29 28 30 sessionLists = cherrypy.config.getAll('sessionFilter.sessionList') 29 31 32 # loop across all paths with session listts 30 33 for sessionPath, sessionList in sessionLists.iteritems(): 34 35 # if it isn't a list make it one 31 36 if not isinstance(sessionList,list): 32 37 sessionList=[sessionList] 33 38 34 39 for index in xrange(len(sessionList)): 40 35 41 session = sessionList[index] 36 42 43 # check if the session is a string, if it is 44 # try and match it to a storage adaptor and replace 45 # the string in the list with the initilized adaptor 37 46 if isinstance(session, str): 38 47 sessionName = session 39 # check if the session is on or off48 # if the session is off skip to the next session in the list 40 49 if not cherrypy.config.get('sessionFilter.%s.on' % sessionName, True): 41 50 continue 42 51 52 # look up the storage type or return the default 43 53 storageType = sessionconfig.retrieve('storageType', sessionName) 44 54 45 sessionManager = _sessionTypes[storageType](sessionName) 55 # try to initilize a built in session 56 try: 57 sessionManager = _sessionTypes[storageType](sessionName) 58 except KeyError: 59 # the storageType is not built in 60 try: 61 sessionManger = cherrypy._cputil.getSpecialAttribute(storageType)(sessionName) 62 except cherrypy.InternalError: 63 # it is not a built in session and the adaptor has not been 64 # set as an attribute in the CherryPy tree 65 raise SessionBadStorageTypeError(storageType) 66 67 68 # we need to remember the path 46 69 sessionManager.path = sessionPath 70 71 # the session is born clean 47 72 sessionManager.lastCleanUp = time.time() 48 73 74 # replace the entry in the session list 49 75 sessionList[index] = sessionManager 50 76 77 # put then new session list back in the config map 51 78 cherrypy.config.update({sessionPath: {'sessionFilter.sessionList' : sessionList} }) 52 79 else: 53 80 sessionManager = session 54 81 55 sessions [sessionManager.sessionName] = sessionManager82 sessions.append(sessionManager) 56 83 57 84 return sessions 58 59 _getSessions2 = _getSessions360 61 85 62 86 class SessionFilter: … … 66 90 67 91 def __initSessions(self): 68 sessions = _getSessions2()69 # sessions = _getSessions() 92 93 # look up all of the session keys by cookie 70 94 sessionKeys = self.getSessionKeys() 71 95 72 for session Name in sessions:73 session Manager = sessions[sessionName]96 for sessionManager in _getSessions(): 97 sessionName = sessionManager.sessionName 74 98 sessionKey = sessionKeys.get(sessionName, None) 75 99 … … 86 110 Returns the all current sessionkeys as a dict 87 111 """ 112 88 113 sessionKeys = {} 89 sessions = _getSessions2()90 for session Name in sessions:91 session Manager = sessions[sessionName]114 115 for sessionManager in _getSessions(): 116 sessionName = sessionManager.sessionName 92 117 93 118 cookiePrefix = sessionconfig.retrieve('cookiePrefix', sessionName, None) … … 102 127 def setSessionKey(self, sessionKey, sessionManager): 103 128 """ 104 Sets the session key in a cookie. Aplications should not call this function, 105 but it might be usefull to redefine it. 129 Sets the session key in a cookie. 106 130 """ 107 131 … … 114 138 cherrypy.response.simpleCookie[cookieName]['version'] = 1 115 139 140 # if we do not have a manually defined cookie path use path where the session 141 # manager was defined 116 142 cookiePath = sessionconfig.retrieve('cookiePath', sessionManager.sessionName, sessionManager.path) 117 143 … … 119 145 120 146 def __saveSessions(self): 121 #sessions = _getSessions()122 sessions = _getSessions2()123 147 124 for sessionName in sessions: 125 sessionManager = sessions[sessionName] 148 for sessionManager in _getSessions(): 149 sessionName = sessionManager.sessionName 150 126 151 sessionData = getattr(cherrypy.sessions, sessionName) 127 152 sessionManager.commitCache(sessionData.key) … … 146 171 self.__saveSessions() 147 172 148 '''149 173 #this breaks a test case 150 174 def beforeErrorResponse(self): … … 152 176 if not cherrypy.config.get('staticFilter.on', False) and \ 153 177 cherrypy.config.get('sessionFilter.on'): 154 '''178 self.__saveSessions() trunk/cherrypy/lib/filter/sessionfilter/sessionerrors.py
r375 r392 57 57 58 58 def __str__(self): 59 return "Could not find %s storage type." 59 return "Could not find %s storage type." % self.storageType 60 60 trunk/cherrypy/tutorial/tut09_sessionfilter.py
r382 r392 5 5 import cherrypy 6 6 7 # you will never need to import the RamSession8 # we only import it to demostrate how to manually use9 # a storage adaptor as would with a customized storage adaptor10 from cherrypy.lib.filter.sessionfilter.ramsession import RamSession11 12 7 class HitCounter: 13 8 trunk/cherrypy/tutorial/tutorial.conf
r315 r392 3 3 server.threadPool = 10 4 4 server.environment = "production" 5 session .storageType= "ram"5 sessionFilter.default.storageType= "ram" 6 6 # server.logToScreen = False

