Ticket #3655: irequestfilter_patch_3689.3.diff
| File irequestfilter_patch_3689.3.diff, 2.9 KB (added by cboos, 6 years ago) |
|---|
-
trac/web/api.py
467 467 requests, before and/or after they are processed by the main handler.""" 468 468 469 469 def pre_process_request(req, handler): 470 """ Do any pre-processing the request might need; typically adding471 values to req.hdf, or redirecting.470 """Called after initial handler selection, and can be used to change 471 the selected handler or redirect request. 472 472 473 473 Always returns the request handler, even if unchanged. 474 474 """ -
trac/web/main.py
201 201 # Prepare HDF for the clearsilver template 202 202 try: 203 203 use_template = getattr(chosen_handler, 'use_template', True) 204 req.hdf = None 204 205 if use_template: 205 206 chrome = Chrome(self.env) 206 207 req.hdf = HDFWrapper(loadpaths=chrome.get_all_templates_dirs()) … … 211 212 if not early_error: 212 213 raise 213 214 215 def post_process_request(resp=(None, None)): 216 for filter_ in reversed(self.filters): 217 resp = filter_.post_process_request(req, *resp) 218 return resp 219 220 def post_process_after_error(): 221 try: 222 post_process_request() 223 except Exception, e: 224 self.log.exception(e) 225 214 226 if early_error: 227 post_process_after_error() 215 228 raise early_error[0], early_error[1], early_error[2] 216 229 217 230 # Process the request and render the template 218 231 try: 219 232 try: 220 resp = chosen_handler.process_request(req) 221 if resp: 222 for filter_ in reversed(self.filters): 223 resp = filter_.post_process_request(req, *resp) 224 template, content_type = resp 225 req.display(template, content_type or 'text/html') 226 else: 227 for filter_ in reversed(self.filters): 228 filter_.post_process_request(req, None, None) 233 try: 234 resp = chosen_handler.process_request(req) 235 if resp: 236 template, content_type = post_process_request(resp) 237 req.display(template, content_type or 'text/html') 238 else: 239 post_process_request() 240 except: 241 post_process_after_error() 242 err = sys.exc_info() 243 raise err[0], err[1], err[2] 229 244 except PermissionError, e: 230 245 raise HTTPForbidden(to_unicode(e)) 231 246 except TracError, e:
