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

Changeset 1235

Show
Ignore:
Timestamp:
08/11/06 15:27:04
Author:
fumanchu
Message:

More-explicit error when illegally passing positional arguments to tool decorators. Also, a new tool test for multiple decorators with kwargs.

Files:

Legend:

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

    r1232 r1235  
    6363        return conf 
    6464     
    65     def __call__(self, **kwargs): 
     65    def __call__(self, *args, **kwargs): 
    6666        """Compile-time decorator (turn on the tool in config). 
    6767         
     
    7373            whats_my_base.exposed = True 
    7474        """ 
     75        if args: 
     76            raise TypeError("The %r Tool does not accept positional " 
     77                            "arguments; you must use keyword arguments." 
     78                            % self._name) 
    7579        def wrapper(f): 
    7680            if not hasattr(f, "_cp_config"): 
  • trunk/cherrypy/test/test_tools.py

    r1147 r1235  
    8585        pipe.exposed = True 
    8686        pipe._cp_config = {'hooks.before_request_body': pipe_body} 
     87         
     88        # Multiple decorators; include kwargs just for fun. 
     89        def decorated_euro(self): 
     90            yield u"Hello," 
     91            yield u"world" 
     92            yield europoundUnicode 
     93        decorated_euro.exposed = True 
     94        decorated_euro = tools.gzip(compress_level=6)(decorated_euro) 
     95        decorated_euro = tools.encode(errors='ignore')(decorated_euro) 
    8796     
    8897    root = Root() 
     
    222231        self.getPage("/euro", headers=[("Accept-Encoding", "gzip")]) 
    223232        self.assertInBody(zbuf.getvalue()[:3]) 
     233         
     234        zbuf = StringIO.StringIO() 
     235        zfile = gzip.GzipFile(mode='wb', fileobj=zbuf, compresslevel=6) 
     236        zfile.write(expectedResult) 
     237        zfile.close() 
     238         
     239        self.getPage("/decorated_euro", headers=[("Accept-Encoding", "gzip")]) 
     240        self.assertInBody(zbuf.getvalue()[:3]) 
    224241     
    225242    def testBareHooks(self): 

Hosted by WebFaction

Log in as guest/cpguest to create tickets