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

Changeset 1707

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

Better fix for #680.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/cherrypy-3.0.x/cherrypy/lib/sessions.py

    r1611 r1707  
    396396def save(): 
    397397    """Save any changed session data.""" 
     398     
     399    if not hasattr(cherrypy._serving, "session"): 
     400        return 
     401     
    398402    # Guard against running twice 
    399403    if hasattr(cherrypy.request, "_sessionsaved"): 
     
    415419def close(): 
    416420    """Close the session object for this request.""" 
    417     sess = cherrypy.session 
    418     if sess.locked: 
     421    sess = getattr(cherrypy._serving, "session", None) 
     422    if sess and sess.locked: 
    419423        # If the session is still locked we release the lock 
    420424        sess.release_lock() 
  • branches/cherrypy-3.0.x/cherrypy/test/test_session.py

    r1596 r1707  
    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