Changeset 1196
- Timestamp:
- 07/10/06 23:13:50
- Files:
-
- trunk/cherrypy/_cptools.py (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/cherrypy/_cptools.py
r1190 r1196 52 52 53 53 def _merged_args(self, d=None): 54 conf = cherrypy.request.toolmap.get(self._name, {}).copy() 55 conf.update(d or {}) 54 tm = cherrypy.request.toolmap 55 if self._name in tm: 56 conf = tm[self._name].copy() 57 else: 58 conf = {} 59 if d: 60 conf.update(d) 56 61 if "on" in conf: 57 62 del conf["on"] … … 113 118 return wrapper 114 119 120 def _wrapper(self): 121 if self.callable(**self._merged_args()): 122 cherrypy.request.handler = None 123 115 124 def _setup(self): 116 125 """Hook this tool into cherrypy.request. … … 119 128 method when the tool is "turned on" in config. 120 129 """ 121 def wrapper():122 if self.callable(**self._merged_args()):123 cherrypy.request.handler = None124 130 # Don't pass conf (or our wrapper will get wrapped!) 125 cherrypy.request.hooks.attach(self._point, wrapper)131 cherrypy.request.hooks.attach(self._point, self._wrapper) 126 132 127 133 … … 132 138 Tool.__init__(self, None, callable, name) 133 139 140 def _wrapper(self): 141 self.callable(**self._merged_args()) 142 134 143 def _setup(self): 135 144 """Hook this tool into cherrypy.request. … … 138 147 method when the tool is "turned on" in config. 139 148 """ 140 def wrapper(): 141 self.callable(**self._merged_args()) 142 cherrypy.request.error_response = wrapper 149 cherrypy.request.error_response = self._wrapper 143 150 144 151 … … 148 155 from cherrypy.lib import sessions as _sessions, xmlrpc as _xmlrpc 149 156 from cherrypy.lib import caching as _caching, wsgiapp as _wsgiapp 150 151 152 class StaticDirTool(MainTool):153 def _setup(self):154 """Hook this tool into cherrypy.request using the given conf."""155 conf = self._merged_args()156 def wrapper():157 if self.callable(**conf):158 cherrypy.request.handler = None159 # Don't pass conf (or our wrapper will get wrapped!)160 cherrypy.request.hooks.attach(self._point, wrapper)161 157 162 158 … … 172 168 setattr(self, k, None) 173 169 170 def _init(self): 171 conf = cherrypy.request.toolmap.get(self._name, {}) 172 173 s = cherrypy.request._session = _sessions.Session() 174 # Copy all conf entries onto Session object attributes 175 for k, v in conf.iteritems(): 176 setattr(s, str(k), v) 177 s.init() 178 179 if not hasattr(cherrypy, "session"): 180 cherrypy.session = _sessions.SessionWrapper() 181 174 182 def _setup(self): 175 183 """Hook this tool into cherrypy.request using the given conf. … … 178 186 method when the tool is "turned on" in config. 179 187 """ 180 def init():181 conf = cherrypy.request.toolmap.get(self._name, {})182 183 s = cherrypy.request._session = _sessions.Session()184 # Copy all conf entries onto Session object attributes185 for k, v in conf.iteritems():186 setattr(s, str(k), v)187 s.init()188 189 if not hasattr(cherrypy, "session"):190 cherrypy.session = _sessions.SessionWrapper()191 188 # init must be bound after headers are read 192 cherrypy.request.hooks.attach('before_request_body', init)189 cherrypy.request.hooks.attach('before_request_body', self._init) 193 190 cherrypy.request.hooks.attach('before_finalize', _sessions.save) 194 191 cherrypy.request.hooks.attach('on_end_request', _sessions.cleanup) … … 236 233 """Hook this tool into cherrypy.request using the given conf.""" 237 234 request = cherrypy.request 235 # Guard against running this method twice. 238 236 if hasattr(request, 'xmlrpc'): 239 237 return … … 303 301 default_toolbox.encode = Tool('before_finalize', encoding.encode) 304 302 default_toolbox.gzip = Tool('before_finalize', encoding.gzip) 305 default_toolbox.staticdir = StaticDirTool(static.staticdir)303 default_toolbox.staticdir = MainTool(static.staticdir) 306 304 default_toolbox.staticfile = MainTool(static.staticfile) 307 305 default_toolbox.sessions = SessionTool()

