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

Changeset 1542

Show
Ignore:
Timestamp:
12/21/06 01:11:10
Author:
fumanchu
Message:

Fix for #595 (Allow tool priorities to be overridden in config).

Files:

Legend:

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

    r1495 r1542  
    101101        method when the tool is "turned on" in config. 
    102102        """ 
    103         p = getattr(self.callable, "priority", self._priority) 
     103        conf = self._merged_args() 
     104        p = conf.pop("priority", None) 
     105        if p is None: 
     106            p = getattr(self.callable, "priority", self._priority) 
    104107        cherrypy.request.hooks.attach(self._point, self.callable, 
    105                                       priority=p, **self._merged_args()
     108                                      priority=p, **conf
    106109 
    107110 
     
    142145        method when the tool is "turned on" in config. 
    143146        """ 
    144         p = getattr(self.callable, "priority", self._priority) 
     147        conf = self._merged_args() 
     148        p = conf.pop("priority", None) 
     149        if p is None: 
     150            p = getattr(self.callable, "priority", self._priority) 
    145151        cherrypy.request.hooks.attach(self._point, self._wrapper, 
    146                                       priority=p, **self._merged_args()
     152                                      priority=p, **conf
    147153 
    148154 
     
    269275        """Hook caching into cherrypy.request.""" 
    270276        conf = self._merged_args() 
    271         cherrypy.request.hooks.attach('before_handler', self._wrapper, **conf) 
     277         
     278        p = conf.pop("priority", None) 
     279        cherrypy.request.hooks.attach('before_handler', self._wrapper, 
     280                                      priority=p, **conf) 
    272281 
    273282 
  • trunk/cherrypy/test/test_tools.py

    r1530 r1542  
    104104         
    105105        # Multiple decorators; include kwargs just for fun. 
    106         # XXX Note that encode must run before gzip. 
    107         def decorated_euro(self): 
     106        # Note that encode must run before gzip. 
     107        def decorated_euro(self, *vpath): 
    108108            yield u"Hello," 
    109109            yield u"world" 
     
    193193            'tools.gzip.on': True, 
    194194            'tools.encode.on': True, 
     195        }, 
     196        # Priority specified in config 
     197        '/decorated_euro/subpath': { 
     198            'tools.gzip.priority': 10, 
    195199        }, 
    196200    } 
     
    289293        self.getPage("/decorated_euro", headers=[("Accept-Encoding", "gzip")]) 
    290294        self.assertInBody(zbuf.getvalue()[:3]) 
     295         
     296        # This should break because gzip's priority was lowered in conf. 
     297        # Of course, we don't want breakage in production apps, 
     298        # but it proves the priority was changed. 
     299        self.getPage("/decorated_euro/subpath", 
     300                     headers=[("Accept-Encoding", "gzip")]) 
     301        self.assertErrorPage(500, pattern='UnicodeEncodeError') 
    291302     
    292303    def testBareHooks(self): 

Hosted by WebFaction

Log in as guest/cpguest to create tickets