diff options
| author | Chris McDonough <chrism@agendaless.com> | 2009-06-21 19:54:16 +0000 |
|---|---|---|
| committer | Chris McDonough <chrism@agendaless.com> | 2009-06-21 19:54:16 +0000 |
| commit | 5e939a9a86f42318f1e92419cec23f49ec5b76f6 (patch) | |
| tree | 7054a9661dafc3090e713b2939a2b574cadb8b24 /repoze/bfg/urldispatch.py | |
| parent | 588c64277429e144a531704833c40ef8c6bd0007 (diff) | |
| download | pyramid-5e939a9a86f42318f1e92419cec23f49ec5b76f6.tar.gz pyramid-5e939a9a86f42318f1e92419cec23f49ec5b76f6.tar.bz2 pyramid-5e939a9a86f42318f1e92419cec23f49ec5b76f6.zip | |
- Make Routes mapper responsible for doing magic to fix up PATH_INFO
and SCRIPT_NAME when a ``path_info`` key exists in the matchdict.
This used to be done in the traverser, which made no sense.
Diffstat (limited to 'repoze/bfg/urldispatch.py')
| -rw-r--r-- | repoze/bfg/urldispatch.py | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/repoze/bfg/urldispatch.py b/repoze/bfg/urldispatch.py index bfeae3333..dcd4af208 100644 --- a/repoze/bfg/urldispatch.py +++ b/repoze/bfg/urldispatch.py @@ -1,3 +1,5 @@ +import re + from routes import Mapper from routes import request_config @@ -45,6 +47,21 @@ class RoutesRootFactory(Mapper): environ['wsgiorg.routing_args'] = ((), args) environ['bfg.routes.route'] = route environ['bfg.routes.matchdict'] = args + # this is stolen from routes.middleware; if the route map + # has a *path_info capture, use it to influence the path + # info and script_name of the generated environment + if 'path_info' in args: + if not 'SCRIPT_NAME' in environ: + environ['SCRIPT_NAME'] = '' + oldpath = environ['PATH_INFO'] + newpath = args['path_info'] or '' + environ['PATH_INFO'] = newpath + if not environ['PATH_INFO'].startswith('/'): + environ['PATH_INFO'] = '/' + environ['PATH_INFO'] + pattern = r'^(.*?)/' + re.escape(newpath) + '$' + environ['SCRIPT_NAME'] += re.sub(pattern, r'\1', oldpath) + if environ['SCRIPT_NAME'].endswith('/'): + environ['SCRIPT_NAME'] = environ['SCRIPT_NAME'][:-1] factory = route._factory or self.default_root_factory return factory(environ) |
