Anonymous avatar Anonymous committed 4ef357f

SessionFilter improvements

Comments (0)

Files changed (5)

cherrypy/_cpconfig.py

         
 import os.path
 
-def getAll(key):
+def getAll(key, asList = False):
     """
     getAll will lookup the key in the current node and all of its parent nodes,
     it will return a dictionary paths of each node containing the key and its value
     if path == '/' and value != None:
         result[path] = value
     
-    return result
+    if asList:
+        return [(path, result[path]) for path in result]
+    else:
+        return result
 
 class CaseSensitiveConfigParser(ConfigParser.ConfigParser):
     """ Sub-class of ConfigParser that keeps the case of options and

cherrypy/lib/filter/sessionfilter/basesession.py

 
 from sessiondict import SimpleSessionDict
 
+import sessionconfig
+
 class BaseSession(object):
     """
     This is the class from which all session storage types are derived.
     def getDefaultAttributes(self):
       return { 
                'timestamp'  : int(time.time()),
-               'timeout'    : cherrypy.cpg.config.get('sessionFilter.timeout') * 60,
+               'timeout'    : sessionconfig.get('timeout', self.sessionName) * 60,
                'lastAccess' : int(time.time()),
-               'key' : self.generateSessionId()
+               'key' : self.generateSessionKey()
              }
        
     def newSession(self):
         newData.update(self.defaultValues)
         return SimpleSessionDict(newData)
 
-    def generateSessionId(self):
+    def generateSessionKey(self):
         """ Function to return a new sessioId """
-        cpg = cherrypy.cpg
-        sessionKeyFunc = cpg.config.get('%s.keyMaker' % self.sessionName, None)
+        sessionKeyFunc = sessionconfig.get('keyGenerator', self.sessionName, None)
         
         if sessionKeyFunc:
             newKey = cherrypy._cputil.getSpecialAttribute(sessionKeyFunc)()
         return session.key
 
     def commitCache(self, sessionKey): 
-        cpg = cherrypy.cpg 
         
         session = self.__sessionCache[sessionKey]
         session.threadCount = 0
         self.setSession(session)
         
-        cacheTimeout = cpg.config.get('sessionFilter.cacheTimeout', None)
+        cacheTimeout = sessionconfig.get('%s.cacheTimeout' % self.sessionName, None)
+        if not cacheTimeout:
+            cacheTimeout = sessionconfig.get('sessionFilter.cacheTimeout', None)
         
         if session.threadCount == 0 and not cacheTimeout:
             del self.__sessionCache[sessionKey]
     def cleanUpCache(self):
         """ cleanup all inactive sessions """
         
-        cacheTimeout = cpg.config.get('sessionFilter.cacheTimeout', None)
+        cacheTimeout = sessionconfig.get('%s.cacheTimeout' % self.sessionName, None)
         
         # don't waste cycles if we aren't caching inactive sessions
         if cacheTimeout:
         self.delSession()
         """ delete a session from storage """
 
-    def register(cls):
-        """
-        This method will place the configName and session object so
-        the configuration system will know that "BaseSession" maps to
-        the BaseSession class
-        """
-        cherrypy.cpg.session.registerSession(cls.configName, cls)
-    register=classmethod(register)
-
     def cleanUpOldSessions(self):
         """This function cleans up expired sessions"""
 

cherrypy/lib/filter/sessionfilter/dbmsession.py

 
         BaseSession.__init__(self, sessionName)
         
-        sessionName=cpg.config.get('session.new', None)
-        sessionFile=cpg.config.get('%s.dbFile' % sessionName, 'shelfSession.db')
+        sessionName=cpg.config.get('sessionFilter.new', None)
+        sessionFile=cpg.config.get('%s.dbFile' % sessionName, '%s.db' % sessionName)
         self.__data = shelve.open(sessionFile, 'c')
 
     def getSession(self, sessionKey):

cherrypy/lib/filter/sessionfilter/filesession.py

 import os.path
 
 from sessionerrors import *
+import sessionconfig
 
 import threading
 
 
     def __storageDir(self):
         cpg = cherrypy.cpg
-        storageDir = cpg.config.get('%s.storageFileDir' % self.sessionName)
-        if not storageDir:
-            storageDir = cpg.config.get('sessionFilter.storageFileDir', '.sessionFiles')
+        storageDir = sessionconfig.get('storageFileDir', self.sessionName, '.sessionFiles')
         return storageDir
     
     # all session writes are blocked 

cherrypy/lib/filter/sessionfilter/sessionfilter.py

 
 from sessionerrors import SessionNotFoundError 
 
-from ramsession  import RamSession 
-from filesession import FileSession
-from dbmsession  import DBMSession
-
-_sessionTypes = {
-                  'ram'       : RamSession,
-                  'file'      : FileSession,
-                  'anydb'     : DBMSession
-                }
-
-try:
-    # the user might not have sqlobject instaled
-    from sqlobjectsession  import SQLObjectSession
-    _sessionTypes['sqlobject']  = SQLObjectSession
-except ImportError:
-    pass
-    
+import sessionconfig 
 
 def _getSessions():
     """ checks the config file for the sessions """
         sessionName = sessionNames[sessionPath]
         sessionManager = cpg.config.get('%s.sessionManager' % sessionName, None)
         if not sessionManager:
-            storageType = cpg.config.get('%s.storageType' % sessionName, 'ram')
+            storageType = sessionconfig.get('storageType', sessionName)
             
-            #sessionManager = _sessionTypes[storageType](sessionName)
             try:
-                sessionManager = _sessionTypes[storageType](sessionName)
+                sessionManager = sessionconfig._sessionTypes[storageType](sessionName)
             except KeyError:
                 storageType = cpg.config.get('%s.customStorageClass' % sessionName)
                 if storageType:
                     try:
-                        cherrypy._cputil.getSpecialAttribute(storageType)
+                        storageClass = cherrypy._cputil.getSpecialAttribute(storageType)
+                        sessionManager = storageClass(sessionName)
                     except cherrypy.cperror.InternalError:
                         raise SessionBadStorageTypeError(storageType)
                 raise
                               }
                              )
         else: # try and clean up
-            cleanUpDelay = cpg.config.get('session.cleanUpDelay')
+            cleanUpDelay = sessionconfig.get('cleanUpDelay', sessionName)
             now = time.time()
             lastCleanUp = sessionManager.lastCleanUp
             if lastCleanUp + cleanUpDelay * 60 <= now:
             sessionName = sessions[sessionPath]
             cookieName = cpg.config.get('%s.cookieName' % sessionName, None)
             if not cookieName:
-                cookieName = cpg.config.get('session.cookieName') + '|' + re.sub('/','_', sessionPath) + '|' + sessionName
+                cookieName = cpg.config.get('sessionFilter.cookieName') + '|' + sessionName + '|' + re.sub('/','_', sessionPath)
                 cpg.config.update({
                                     sessionPath : {'%s.cookieName' % sessionName : cookieName}
                                   })
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.