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

Changeset 377

Show
Ignore:
Timestamp:
06/24/05 18:14:06
Author:
mikerobi
Message:

no more _cpSessionList, use 'sessionFilter.sessionList'=[] in the config system

Files:

Legend:

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

    r375 r377  
    3535 
    3636    'sessionFilter.on' : False, 
    37      
     37    'sessionFilter.sessionsList' : ['default'], 
    3838    'sessionFilter.default.on': True, 
    3939    'sessionFilter.default.timeout': 60, 
    4040    'sessionFilter.default.cleanUpDelay': 60, 
    4141    'sessionFilter.default.storageType' : 'ram', 
    42     'sessionFilter.default.cookieName': 'CherryPySession', 
     42    'sessionFilter.default.cookiePrefix': 'CherryPySession', 
    4343    'sessionFilter.default.storageFileDir': '.sessionFiles' 
    4444    } 
  • trunk/cherrypy/_cputil.py

    r375 r377  
    4444    root = getattr(cpg, 'root', None) 
    4545    if root: 
    46         objectTrail = [cpg, root] 
     46        objectTrail = [root] 
    4747        # Try object path 
    4848        try: 
     
    8383        return globals()[name] 
    8484    except KeyError: 
    85         raise cperror.InternalError("Special function %s could not be found" 
     85        raise cperror.InternalError("Special attribute %s could not be found" 
    8686                                    % repr(name)) 
    8787 
  • trunk/cherrypy/lib/filter/sessionfilter/sessionconfig.py

    r375 r377  
    3737                } 
    3838 
     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 
    3950try: 
    4051    # the user might not have sqlobject instaled 
  • trunk/cherrypy/lib/filter/sessionfilter/sessionfilter.py

    r375 r377  
    88import sessionconfig  
    99from cherrypy._cputil import getObjectTrail 
     10def _getSessions3(): 
     11    cpg = cherrypy.cpg 
     12    sessions = {} 
     13     
     14    sessionLists = cpg.config.getAll('sessionFilter.sessionsList') 
    1015 
    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 
    1427 
    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() 
    2233 
    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} }) 
    3037            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() 
    3643 
    37             if isinstance(sessionManager, dict): 
    38                 # must be initilized 
    39                 sessionName   = sessionManager['sessionName'] 
    40                 compatible    = sessionManager.get('compatible',  []) 
    41                 incompatible  = sessionManager.get('icompatible', []) 
    42                 
    43                 # unless it is off initilize 
    44                 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 SessionIncompatibleError 
    51                      
    52                     sessionManager = sessionconfig._sessionTypes[storageType](sessionName) 
    53                     sessionManager.lastCleanUp = time.time() 
    54                     sessionManager.path = objPath 
    55      
    56                     obj._cpSessionList[sessionIndex] = sessionManager 
    57  
    58             elif isinstance(sessionManager, str): 
    59                 # unless it is off initilize 
    60                 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 = objPath 
    66                     obj._cpSessionList[sessionIndex] = sessionManager 
    67                  
    68              
    69             else: # try and clean up 
    7044                cleanUpDelay = sessionconfig.retrieve('cleanUpDelay', sessionManager.sessionName) 
    7145                now = time.time() 
     
    7347                if lastCleanUp + cleanUpDelay * 60 <= now: 
    7448                    sessionManager.cleanUpOldSessions() 
    75              
     49 
    7650            sessions[sessionManager.sessionName] = sessionManager 
     51 
     52    return sessions 
    7753     
    78     return sessions 
     54_getSessions2 = _getSessions3 
    7955 
    8056class SessionFilter: 
     
    8258    Input filter - get the sessionId (or generate a new one) and load up the session data 
    8359    """ 
    84   
     60 
    8561    def __initSessions(self): 
    8662        cpg = cherrypy.cpg 
     
    11187            sessionManager = sessions[sessionName] 
    11288 
    113             cookiePrefix = sessionconfig.retrieve('cookieName', sessionName, None) 
     89            cookiePrefix = sessionconfig.retrieve('cookiePrefix', sessionName, None) 
    11490             
    11591            cookieName = '%s_%s_%i' % (cookiePrefix, sessionName, hash(sessionManager)) 
     
    132108        sessionName = sessionManager.sessionName 
    133109         
    134         cookiePrefix = sessionconfig.retrieve('cookieName', sessionName, None) 
     110        cookiePrefix = sessionconfig.retrieve('cookiePrefix', sessionName, None) 
    135111         
    136112        cookieName = '%s_%s_%i' % (cookiePrefix, sessionName, hash(sessionManager)) 
     
    139115        cpg.response.simpleCookie[cookieName]['version'] = 1 
    140116         
    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 
    142120 
    143121     
  • trunk/cherrypy/tutorial/tut09_sessionfilter.py

    r375 r377  
    1111  
    1212class 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                }) 
    1823 
    1924    # this is just a primative template function 
     
    6267     
    6368    admin.exposed = True 
    64     admin._cpSessionList=['admin'] 
    6569     
    6670    def forum(self): 
     
    7781     
    7882    forum.exposed=True 
    79     forum._cpSessionList=['forum'] 
    8083 
    8184cpg.root = HitCounter() 
     
    8386if __name__ == '__main__': 
    8487    cpg.config.update(file = "tutorial.conf") 
    85     cpg.config.update(file = 'tut10_sessionfilter.conf') 
    8688    cpg.server.start() 
    8789 

Hosted by WebFaction

Log in as guest/cpguest to create tickets