# HG changeset patch # User Jeff Hammel # Date 1321558579 28800 # Node ID bb66c9a62be9bae863e983e71da5a3d8d1872d89 # Parent 89047fd9ea8f55e0e9398c1aa602724dea298b33 unfutz the environ if the resource is not found diff -r 89047fd9ea8f -r bb66c9a62be9 wsgintegrate/match.py --- a/wsgintegrate/match.py Thu Nov 17 11:26:33 2011 -0800 +++ b/wsgintegrate/match.py Thu Nov 17 11:36:19 2011 -0800 @@ -3,6 +3,7 @@ these are just a sample; you can add arbitrary match objects if desired """ +from webob import Request from webob import exc class RequestMatch(object): @@ -53,10 +54,21 @@ script_name, path_info = match # fix up the environment for downstream applications + _script_name = environ.get('SCRIPT_NAME') + _path_info = environ.get('PATH_INFO') environ['SCRIPT_NAME'] = script_name environ['PATH_INFO'] = path_info - return self.app(environ, start_response) + request = Request(environ) + response = request.get_response(self.app) + + # unfutz the environ if the resource is not found + if response.status_int == 404: + if _script_name is not None: + environ['SCRIPT_NAME'] = script_name + environ['PATH_INFO'] = _path_info + + return response(environ, start_response) class MatchMethod(RequestMatch): """match based on request method""" @@ -66,13 +78,13 @@ if isinstance(methods, basestring): methods = methods.split() self.methods = set(methods) - + def condition(self, environ): return environ['REQUEST_METHOD'] in self.methods class MatchHost(RequestMatch): """match based on the host and port""" - + def __init__(self, app, host, port=None): RequestMatch.__init__(self, app) self.host = host