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

Changeset 392

Show
Ignore:
Timestamp:
06/27/05 22:36:45
Author:
mikerobi
Message:

nicer config.getAll, config.get no longer has a startPath, outputConfigMap is cleaner and it no longer logs erroneous static content and session content information. Several sessionFilter files renamed

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/cherrypy/config.py

    r382 r392  
    9090        _load(file) 
    9191 
    92 def get(key, defaultValue=None, returnSection=False, startPath = None): 
     92def get(key, defaultValue=None, returnSection=False): 
    9393    # 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 = "/" 
    10299     
    103100    while True: 
     
    135132    This function is required by the session filter 
    136133    """ 
    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        
    152161 
    153162class CaseSensitiveConfigParser(ConfigParser.ConfigParser): 
     
    197206def outputConfigMap(): 
    198207    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  
    44 
    55import sessionconfig 
    6 from sessionerrors import SessionNotFoundError, SessionIncompatibleError 
    7 from ramsession import RamSession 
    8 from filesession import FileSession 
    9 from dbmsession import DBMSession 
     6 
     7from sessionerrors import SessionNotFoundError, SessionIncompatibleError, SessionBadStorageTypeError 
     8from ramadaptor import RamSession 
     9from fileadaptor import FileSession 
     10from anydbadaptor import DBMSession 
    1011 
    1112_sessionTypes = { 
     
    2324 
    2425 
    25 def _getSessions3(): 
    26     sessions = {} 
     26# this function gets all active sessions based on the path 
     27def _getSessions(): 
     28    sessions = [] 
    2729     
    2830    sessionLists = cherrypy.config.getAll('sessionFilter.sessionList') 
    2931     
     32    # loop across all paths with session listts 
    3033    for sessionPath, sessionList in sessionLists.iteritems(): 
     34         
     35        # if it isn't a list make it one 
    3136        if not isinstance(sessionList,list): 
    3237            sessionList=[sessionList] 
    3338         
    3439        for index in xrange(len(sessionList)): 
     40             
    3541            session = sessionList[index] 
    3642             
     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 
    3746            if isinstance(session, str): 
    3847                sessionName = session 
    39                 # check if the session is on or off 
     48                # if the session is off skip to the next session in the list 
    4049                if not cherrypy.config.get('sessionFilter.%s.on' % sessionName, True): 
    4150                    continue 
    4251                 
     52                # look up the storage type or return the default 
    4353                storageType = sessionconfig.retrieve('storageType', sessionName) 
    4454                 
    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 
    4669                sessionManager.path = sessionPath 
     70 
     71                # the session is born clean 
    4772                sessionManager.lastCleanUp = time.time() 
    4873                 
     74                # replace the entry in the session list 
    4975                sessionList[index] = sessionManager 
    5076                 
     77                # put then new session list back in the config map 
    5178                cherrypy.config.update({sessionPath: {'sessionFilter.sessionList' : sessionList} }) 
    5279            else: 
    5380                sessionManager = session 
    5481             
    55             sessions[sessionManager.sessionName] = sessionManager 
     82            sessions.append(sessionManager) 
    5683     
    5784    return sessions 
    58  
    59 _getSessions2 = _getSessions3 
    60  
    6185 
    6286class SessionFilter: 
     
    6690 
    6791    def __initSessions(self): 
    68         sessions = _getSessions2() 
    69 #        sessions = _getSessions() 
     92         
     93        # look up all of the session keys by cookie 
    7094        sessionKeys = self.getSessionKeys() 
    7195         
    72         for sessionName in sessions
    73             sessionManager = sessions[sessionName] 
     96        for sessionManager in _getSessions()
     97            sessionName = sessionManager.sessionName 
    7498            sessionKey = sessionKeys.get(sessionName, None) 
    7599             
     
    86110        Returns the all current sessionkeys as a dict 
    87111        """ 
     112         
    88113        sessionKeys = {} 
    89         sessions = _getSessions2() 
    90         for sessionName in sessions
    91             sessionManager = sessions[sessionName] 
     114         
     115        for sessionManager in _getSessions()
     116            sessionName = sessionManager.sessionName 
    92117             
    93118            cookiePrefix = sessionconfig.retrieve('cookiePrefix', sessionName, None) 
     
    102127    def setSessionKey(self, sessionKey, sessionManager): 
    103128        """  
    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.  
    106130        """ 
    107131         
     
    114138        cherrypy.response.simpleCookie[cookieName]['version'] = 1 
    115139         
     140        # if we do not have a manually defined cookie path use path where the session 
     141        # manager was defined 
    116142        cookiePath = sessionconfig.retrieve('cookiePath', sessionManager.sessionName, sessionManager.path) 
    117143         
     
    119145     
    120146    def __saveSessions(self): 
    121         #sessions = _getSessions() 
    122         sessions = _getSessions2() 
    123147         
    124         for sessionName in sessions: 
    125             sessionManager = sessions[sessionName] 
     148        for sessionManager in _getSessions(): 
     149            sessionName = sessionManager.sessionName 
     150             
    126151            sessionData = getattr(cherrypy.sessions, sessionName) 
    127152            sessionManager.commitCache(sessionData.key) 
     
    146171            self.__saveSessions() 
    147172 
    148     ''' 
    149173    #this breaks a test case 
    150174    def beforeErrorResponse(self): 
     
    152176        if not cherrypy.config.get('staticFilter.on', False) and \ 
    153177            cherrypy.config.get('sessionFilter.on'): 
    154     ''' 
     178            self.__saveSessions() 
  • trunk/cherrypy/lib/filter/sessionfilter/sessionerrors.py

    r375 r392  
    5757 
    5858    def __str__(self): 
    59         return "Could not find %s storage type." 
     59        return "Could not find %s storage type." % self.storageType 
    6060     
  • trunk/cherrypy/tutorial/tut09_sessionfilter.py

    r382 r392  
    55import cherrypy 
    66 
    7 # you will never need to import the RamSession 
    8 # we only import it to demostrate how to manually use 
    9 # a storage adaptor as would with a customized storage adaptor 
    10 from cherrypy.lib.filter.sessionfilter.ramsession import RamSession 
    11   
    127class HitCounter: 
    138 
  • trunk/cherrypy/tutorial/tutorial.conf

    r315 r392  
    33server.threadPool = 10 
    44server.environment = "production" 
    5 session.storageType= "ram" 
     5sessionFilter.default.storageType= "ram" 
    66# server.logToScreen = False 

Hosted by WebFaction

Log in as guest/cpguest to create tickets