Changeset 377
- Timestamp:
- 06/24/05 18:14:06
- Files:
-
- trunk/cherrypy/_cpconfig.py (modified) (1 diff)
- trunk/cherrypy/_cputil.py (modified) (2 diffs)
- trunk/cherrypy/lib/filter/sessionfilter/sessionconfig.py (modified) (1 diff)
- trunk/cherrypy/lib/filter/sessionfilter/sessionfilter.py (modified) (6 diffs)
- trunk/cherrypy/tutorial/tut09_sessionfilter.py (modified) (4 diffs)
- trunk/cherrypy/tutorial/tut10_sessionfilter.conf (deleted)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/cherrypy/_cpconfig.py
r375 r377 35 35 36 36 'sessionFilter.on' : False, 37 37 'sessionFilter.sessionsList' : ['default'], 38 38 'sessionFilter.default.on': True, 39 39 'sessionFilter.default.timeout': 60, 40 40 'sessionFilter.default.cleanUpDelay': 60, 41 41 'sessionFilter.default.storageType' : 'ram', 42 'sessionFilter.default.cookie Name': 'CherryPySession',42 'sessionFilter.default.cookiePrefix': 'CherryPySession', 43 43 'sessionFilter.default.storageFileDir': '.sessionFiles' 44 44 } trunk/cherrypy/_cputil.py
r375 r377 44 44 root = getattr(cpg, 'root', None) 45 45 if root: 46 objectTrail = [ cpg,root]46 objectTrail = [root] 47 47 # Try object path 48 48 try: … … 83 83 return globals()[name] 84 84 except KeyError: 85 raise cperror.InternalError("Special function%s could not be found"85 raise cperror.InternalError("Special attribute %s could not be found" 86 86 % repr(name)) 87 87 trunk/cherrypy/lib/filter/sessionfilter/sessionconfig.py
r375 r377 37 37 } 38 38 39 _sessionDefaults = { 40 'sessionFilter.on' : False, 41 'sessionFilter.SessionsList' : ['default'], 42 'sessionFilter.default.on': True, 43 'sessionFilter.default.timeout': 60, 44 'sessionFilter.default.cleanUpDelay': 60, 45 'sessionFilter.default.storageType' : 'ram', 46 'sessionFilter.default.cookiePrefix': 'CherryPySession', 47 'sessionFilter.default.storageFileDir': '.sessionFiles' 48 } 49 39 50 try: 40 51 # the user might not have sqlobject instaled trunk/cherrypy/lib/filter/sessionfilter/sessionfilter.py
r375 r377 8 8 import sessionconfig 9 9 from cherrypy._cputil import getObjectTrail 10 def _getSessions3(): 11 cpg = cherrypy.cpg 12 sessions = {} 13 14 sessionLists = cpg.config.getAll('sessionFilter.sessionsList') 10 15 11 def _getSessions2(): 12 cpg =cherrypy.cpg 13 sessions = {} 16 for sessionPath, sessionList in sessionLists.iteritems(): 17 if not isinstance(sessionList,list): 18 sessionList=[sessionList] 19 for index in xrange(len(sessionList)): 20 session = sessionList[index] 21 22 if isinstance(session, str): 23 sessionName = session 24 # check if the session is on or off 25 if not cpg.config.get('sessionFilter.%s.on' % sessionName, True): 26 continue 14 27 15 objectTrail = getObjectTrail() 16 17 for n in xrange(len(objectTrail)): 18 obj = objectTrail[n] 19 objPath = '/'.join(cpg.request.path.split('/')[0:n+1]) 20 if not objPath: 21 objPath = '/' 28 storageType = sessionconfig.retrieve('storageType', sessionName) 29 30 sessionManager = sessionconfig._sessionTypes[storageType](sessionName) 31 sessionManager.path = sessionPath 32 sessionManager.lastCleanUp = time.time() 22 33 23 try: 24 sessionList = obj._cpSessionList 25 except AttributeError: 26 27 if obj == cpg: 28 obj._cpSessionList = [{'sessionName':'default'}] 29 sessionList = obj._cpSessionList 34 sessionList[index] = sessionManager 35 36 cpg.config.update({sessionPath: {'sessionFilter.sessionsList' : sessionList} }) 30 37 else: 31 sessionList = []32 33 for sessionIndex in xrange(len(sessionList)):34 sessionManager = sessionList[sessionIndex]35 38 if not cpg.config.get('sessionFilter.%s.on' % session, True): 39 continue 40 41 sessionManager = session 42 sessionManager.lastCleanUp = time.time() 36 43 37 if isinstance(sessionManager, dict):38 # must be initilized39 sessionName = sessionManager['sessionName']40 compatible = sessionManager.get('compatible', [])41 incompatible = sessionManager.get('icompatible', [])42 43 # unless it is off initilize44 if cpg.config.get('sessionFilter.%s.on' % sessionName, True):45 46 storageType = sessionconfig.retrieve('storageType', sessionName)47 48 if compatible and not storageType in compatible or \49 incompatible and not storageType in incompatible:50 raise SessionIncompatibleError51 52 sessionManager = sessionconfig._sessionTypes[storageType](sessionName)53 sessionManager.lastCleanUp = time.time()54 sessionManager.path = objPath55 56 obj._cpSessionList[sessionIndex] = sessionManager57 58 elif isinstance(sessionManager, str):59 # unless it is off initilize60 if cpg.config.get('sessionFilter.%s.on' % sessionManager, True):61 storageType = sessionconfig.retrieve('storageType', sessionManager)62 sessionManager = sessionconfig._sessionTypes[storageType](sessionManager)63 sessionManager.lastCleanUp = time.time()64 65 sessionManager.path = objPath66 obj._cpSessionList[sessionIndex] = sessionManager67 68 69 else: # try and clean up70 44 cleanUpDelay = sessionconfig.retrieve('cleanUpDelay', sessionManager.sessionName) 71 45 now = time.time() … … 73 47 if lastCleanUp + cleanUpDelay * 60 <= now: 74 48 sessionManager.cleanUpOldSessions() 75 49 76 50 sessions[sessionManager.sessionName] = sessionManager 51 52 return sessions 77 53 78 return sessions 54 _getSessions2 = _getSessions3 79 55 80 56 class SessionFilter: … … 82 58 Input filter - get the sessionId (or generate a new one) and load up the session data 83 59 """ 84 60 85 61 def __initSessions(self): 86 62 cpg = cherrypy.cpg … … 111 87 sessionManager = sessions[sessionName] 112 88 113 cookiePrefix = sessionconfig.retrieve('cookie Name', sessionName, None)89 cookiePrefix = sessionconfig.retrieve('cookiePrefix', sessionName, None) 114 90 115 91 cookieName = '%s_%s_%i' % (cookiePrefix, sessionName, hash(sessionManager)) … … 132 108 sessionName = sessionManager.sessionName 133 109 134 cookiePrefix = sessionconfig.retrieve('cookie Name', sessionName, None)110 cookiePrefix = sessionconfig.retrieve('cookiePrefix', sessionName, None) 135 111 136 112 cookieName = '%s_%s_%i' % (cookiePrefix, sessionName, hash(sessionManager)) … … 139 115 cpg.response.simpleCookie[cookieName]['version'] = 1 140 116 141 cpg.response.simpleCookie[cookieName]['path'] = sessionManager.path 117 cookiePath = sessionconfig.retrieve('cookiePath', sessionManager.sessionName, sessionManager.path) 118 119 cpg.response.simpleCookie[cookieName]['path'] = cookiePath 142 120 143 121 trunk/cherrypy/tutorial/tut09_sessionfilter.py
r375 r377 11 11 12 12 class HitCounter: 13 _cpSessionList=[] 14 # this list will contain site wide sessions 15 # in almost all cases this will be defined on a class by class basis, 16 # but for this simple example we use a seperate session list for each method 17 # for simplicity 13 14 def __init__(self): 15 # turn on the sessionfilter and create sessions for the admin 16 # and forum sections of the site 17 cpg.config.update( 18 { 19 'global' : {'sessionFilter.on': True}, 20 '/admin' : {'sessionFilter.sessionsList' : ['admin'] }, 21 '/forum' : {'sessionFilter.sessionsList' : ['forum'] } 22 }) 18 23 19 24 # this is just a primative template function … … 62 67 63 68 admin.exposed = True 64 admin._cpSessionList=['admin']65 69 66 70 def forum(self): … … 77 81 78 82 forum.exposed=True 79 forum._cpSessionList=['forum']80 83 81 84 cpg.root = HitCounter() … … 83 86 if __name__ == '__main__': 84 87 cpg.config.update(file = "tutorial.conf") 85 cpg.config.update(file = 'tut10_sessionfilter.conf')86 88 cpg.server.start() 87 89

