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

Changeset 1708

Show
Ignore:
Timestamp:
08/22/07 12:15:01
Author:
fumanchu
Message:

Better trunk fix for #680 (session init bugs).

Files:

Legend:

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

    r1696 r1708  
    401401def save(): 
    402402    """Save any changed session data.""" 
    403     if not hasattr(cherrypy, "session"): 
     403     
     404    if not hasattr(cherrypy._serving, "session"): 
    404405        return 
    405406     
     
    423424def close(): 
    424425    """Close the session object for this request.""" 
    425     sess = getattr(cherrypy, "session", None) 
     426    sess = getattr(cherrypy._serving, "session", None) 
    426427    if sess and sess.locked: 
    427428        # If the session is still locked we release the lock 
  • trunk/cherrypy/test/test_session.py

    r1596 r1708  
    1010import cherrypy 
    1111from cherrypy.lib import sessions 
     12 
     13def http_methods_allowed(methods=['GET', 'HEAD']): 
     14    method = cherrypy.request.method.upper() 
     15    if method not in methods: 
     16        cherrypy.response.headers['Allow'] = ", ".join(methods) 
     17        raise cherrypy.HTTPError(405) 
     18 
     19cherrypy.tools.allow = cherrypy.Tool('on_start_resource', http_methods_allowed) 
    1220 
    1321 
     
    6876            raise cherrypy.InternalRedirect('/blah') 
    6977        iredir.exposed = True 
     78         
     79        @cherrypy.tools.allow(methods=['GET']) 
     80        def restricted(self): 
     81            return cherrypy.request.method 
     82        restricted.exposed = True 
    7083     
    7184    cherrypy.tree.mount(Root()) 
     
    175188        os.unlink(path) 
    176189        self.getPage('/testStr', self.cookies) 
    177  
     190     
     191    def test_5_Error_paths(self): 
     192        self.getPage('/unknown/page') 
     193        self.assertErrorPage(404, "The path '/unknown/page' was not found.") 
     194         
     195        # Note: this path is *not* the same as above. The above 
     196        # takes a normal route through the session code; this one 
     197        # skips the session code's before_handler and only calls 
     198        # before_finalize (save) and on_end (close). So the session 
     199        # code has to survive calling save/close without init. 
     200        self.getPage('/restricted', self.cookies, method='POST') 
     201        self.assertErrorPage(405, "Specified method is invalid for this server.") 
    178202 
    179203 

Hosted by WebFaction

Log in as guest/cpguest to create tickets