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

Changeset 1621

Show
Ignore:
Timestamp:
02/19/07 14:03:57
Author:
fumanchu
Message:

Test and fix for #661 (Cannot create tool out of an object callable). Also a better docstring for HandlerTool?.

Files:

Legend:

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

    r1608 r1621  
    5050        except (ImportError, AttributeError): 
    5151            pass 
     52        except TypeError: 
     53            if hasattr(self.callable, "__call__"): 
     54                for arg in inspect.getargspec(self.callable.__call__)[0]: 
     55                    setattr(self, arg, None) 
    5256        # IronPython 1.0 raises NotImplementedError because 
    5357        # inspect.getargspec tries to access Python bytecode 
     
    109113    """Tool which is called 'before main', that may skip normal handlers. 
    110114     
    111     The callable provided should return True if processing should skip 
    112     the normal page handler, and False if it should not. 
     115    If the tool successfully handles the request (by setting response.body), 
     116    if should return True. This will cause CherryPy to skip any 'normal' page 
     117    handler. If the tool did not handle the request, it should return False 
     118    to tell CherryPy to continue on and call the normal page handler. If the 
     119    tool is declared AS a page handler (see the 'handler' method), returning 
     120    False will raise NotFound. 
    113121    """ 
    114122     
  • trunk/cherrypy/test/test_tools.py

    r1551 r1621  
    8282        clen = int(cherrypy.request.headers['Content-Length']) 
    8383        cherrypy.request.body = cherrypy.request.rfile.read(clen) 
     84     
     85    # Assert that we can use a callable object instead of a function. 
     86    class Rotator(object): 
     87        def __call__(self, scale): 
     88            r = cherrypy.response 
     89            r.collapse_body() 
     90            r.body = [chr(ord(x) + scale) for x in r.body] 
     91    cherrypy.tools.rotator = cherrypy.Tool('before_finalize', Rotator()) 
    8492     
    8593    class Root: 

Hosted by WebFaction

Log in as guest/cpguest to create tickets