diff options
| author | Chris McDonough <chrism@plope.com> | 2011-04-21 11:46:31 -0400 |
|---|---|---|
| committer | Chris McDonough <chrism@plope.com> | 2011-04-21 11:46:31 -0400 |
| commit | 76071718a63dc86be4bb53713fadbdc618c719ad (patch) | |
| tree | 8741d2198b2725b947bf76500ae8e166c4f1c259 | |
| parent | bcb3312f9faf032bd197a3650d82bad1bf633f4c (diff) | |
| download | pyramid-76071718a63dc86be4bb53713fadbdc618c719ad.tar.gz pyramid-76071718a63dc86be4bb53713fadbdc618c719ad.tar.bz2 pyramid-76071718a63dc86be4bb53713fadbdc618c719ad.zip | |
fewer tests fail
| -rw-r--r-- | pyramid/request.py | 32 | ||||
| -rw-r--r-- | pyramid/static.py | 8 | ||||
| -rw-r--r-- | pyramid/tests/test_wsgi.py | 5 | ||||
| -rw-r--r-- | pyramid/wsgi.py | 5 |
4 files changed, 26 insertions, 24 deletions
diff --git a/pyramid/request.py b/pyramid/request.py index 050828d01..1aceccdba 100644 --- a/pyramid/request.py +++ b/pyramid/request.py @@ -10,6 +10,7 @@ from pyramid.interfaces import IResponseFactory from pyramid.exceptions import ConfigurationError from pyramid.decorator import reify from pyramid.response import Response +from pyramid.traversal import quote_path_segment from pyramid.url import resource_url from pyramid.url import route_url from pyramid.url import static_url @@ -393,11 +394,10 @@ def add_global_response_headers(request, headerlist): response.headerlist.append((k, v)) request.add_response_callback(add_headers) -def copy_request_with_subpath_as_path_info(request, default_script_name='', - default_path_info='/'): - # Make a copy of the request and use the request's subpath (if it exists) - # as the request copy's PATH_INFO. Set the request copy's SCRIPT_NAME to - # the prefix before the subpath. +def subpath_as_path_info(request, default_script_name='',default_path_info='/'): + # Copy the request. Use the request's subpath (if it exists) as the new + # request's PATH_INFO. Set the request copy's SCRIPT_NAME to the prefix + # before the subpath. # # Postconditions: # - SCRIPT_NAME and PATH_INFO are empty or start with / @@ -408,15 +408,18 @@ def copy_request_with_subpath_as_path_info(request, default_script_name='', script_name = request.environ.get('SCRIPT_NAME', '') path_info = request.environ.get('PATH_INFO', '/') - subpath = getattr(request, 'subpath', ()) + new_script_name = default_script_name + new_path_info = default_path_info + + subpath = list(getattr(request, 'subpath', ())) if subpath: # compute new_path_info - default_path_info = '/' + '/'.join(subpath) + new_path_info = '/' + '/'.join([quote_path_segment(x) for x in subpath]) if path_info.endswith('/'): # readd trailing slash stripped by subpath (traversal) # conversion - default_path_info += '/' + new_path_info += '/' # compute new_script_name tmp = [] @@ -424,14 +427,13 @@ def copy_request_with_subpath_as_path_info(request, default_script_name='', while workback: el = workback.pop() if el: - tmp.insert(0, el) + tmp.insert(0, el.decode('utf-8')) if tmp == subpath: - default_script_name = '/'.join(workback) + new_script_name = '/'.join(workback) break - request_copy = request.copy() - - request_copy.environ['SCRIPT_NAME'] = default_script_name - request_copy.environ['PATH_INFO'] = default_path_info + request = request.copy() + request.environ['SCRIPT_NAME'] = new_script_name + request.environ['PATH_INFO'] = new_path_info - return request_copy + return request diff --git a/pyramid/static.py b/pyramid/static.py index 903316deb..c80952129 100644 --- a/pyramid/static.py +++ b/pyramid/static.py @@ -13,7 +13,7 @@ from zope.interface import implements from pyramid.asset import resolve_asset_spec from pyramid.interfaces import IStaticURLInfo from pyramid.path import caller_package -from pyramid.request import copy_request_with_subpath_as_path_info +from pyramid.request import subpath_as_path_info from pyramid.url import route_url class PackageURLParser(StaticURLParser): @@ -211,9 +211,5 @@ class static_view(object): def __call__(self, context, request): script_name = request.environ.get('SCRIPT_NAME', '') path_info = request.environ.get('PATH_INFO', '/') - - request_copy = copy_request_with_subpath_as_path_info(request, - script_name, - path_info) - + request_copy = subpath_as_path_info(request, script_name, path_info) return request_copy.get_response(self.app) diff --git a/pyramid/tests/test_wsgi.py b/pyramid/tests/test_wsgi.py index f63667352..067c86127 100644 --- a/pyramid/tests/test_wsgi.py +++ b/pyramid/tests/test_wsgi.py @@ -110,3 +110,8 @@ class DummyContext: class DummyRequest: def get_response(self, application): return application + + def copy(self): + self.copied = True + return self + diff --git a/pyramid/wsgi.py b/pyramid/wsgi.py index 959f84bbc..ef8863cfa 100644 --- a/pyramid/wsgi.py +++ b/pyramid/wsgi.py @@ -1,5 +1,5 @@ from pyramid.compat import wraps -from pyramid.request import copy_request_with_subpath_as_path_info +from pyramid.request import subpath_as_path_info def wsgiapp(wrapped): """ Decorator to turn a WSGI application into a :app:`Pyramid` @@ -62,8 +62,7 @@ def wsgiapp2(wrapped): up before the application is invoked. """ def decorator(context, request): - request_copy = copy_request_with_subpath_as_path_info(request) + request_copy = subpath_as_path_info(request) return request_copy.get_response(wrapped) - return wraps(wrapped)(decorator) |
