from urllib import unquote from werkzeug.wrappers import BaseResponse as Response class ScriptNameFixer(object): """Sets SCRIPT_NAME from REQUEST_URI.""" def __init__ (self, app): self.app = app def __call__ (self, environ, start_response): uri = unquote(environ["REQUEST_URI"]).split('?', 1)[0] path = environ["PATH_INFO"] if uri.endswith(path): environ["SCRIPT_NAME"] = uri[:-len(path)] return self.app(environ, start_response) def EnvironApp(environ, start_response): """Returns the WSGI environment as response.""" r = Response(str(environ)) return r(environ, start_response)