|In Brief||This is a piece of middleware you can use to filter one app with another. Call it in your middleware.py with:... more|
2 def __init__(self, app, filter, path):
3 self.app = app
4 self.filter = filter
5 self.path = path
7 def __call__(self, environ, start_response):
8 if self.path and environ['PATH_INFO'].startswith(self.path):
9 environ['PATH_INFO'] = environ['PATH_INFO'][len(self.path):] or '/'
10 environ['SCRIPT_NAME'] += self.path
11 return self.filter(environ, start_response)
13 return self.app(environ, start_response)
This is a piece of middleware you can use to filter one app with another. Call it in your middleware.py with:
1app = FilterWith(app, some_other_filter_app, '/path/to/filter/app')
The first app passed will receive the request unless the URL starts with path (here, '/path/to/filter/app'). In that case the second app will receive the request.
This middleware chops off the base path so the filtering application treats the base path as its root, '/'. This middleware also tells your filtering app's Pylons and Routes its base path using SCRIPT_NAME; this path is prepended to any generated URLs. (You'll still have to prepend it manually if you write out any URLs yourself.)