From a5d9943f643f9d4fd7a25f1a9722bf385430b768 Mon Sep 17 00:00:00 2001 From: Chris McDonough Date: Fri, 6 Jan 2012 18:35:18 -0500 Subject: - The ``path_info`` route and view predicates now match against ``request.upath_info`` (Unicode) rather than ``request.path_info`` (indeterminate value based on Python 3 vs. Python 2). This has to be done to normalize matching on Python 2 and Python 3. --- CHANGES.txt | 8 ++++++++ pyramid/config/util.py | 2 +- pyramid/tests/test_config/test_routes.py | 31 +++++++++++++++++++++++++++++-- pyramid/tests/test_config/test_views.py | 4 ++-- 4 files changed, 40 insertions(+), 5 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index d5ef9dd29..65e6cceec 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -8,6 +8,14 @@ Bug Fixes more than one view relied on the defaults being different for configuration conflict resolution. See https://github.com/Pylons/pyramid/issues/394. +Backwards Incompatibilities +--------------------------- + +- The ``path_info`` route and view predicates now match against + ``request.upath_info`` (Unicode) rather than ``request.path_info`` + (indeterminate value based on Python 3 vs. Python 2). This has to be done + to normalize matching on Python 2 and Python 3. + 1.3a4 (2012-01-05) ================== diff --git a/pyramid/config/util.py b/pyramid/config/util.py index 79f13e4a0..6c1bb8368 100644 --- a/pyramid/config/util.py +++ b/pyramid/config/util.py @@ -145,7 +145,7 @@ def make_predicates(xhr=None, request_method=None, path_info=None, except re.error as why: raise ConfigurationError(why.args[0]) def path_info_predicate(context, request): - return path_info_val.match(request.path_info) is not None + return path_info_val.match(request.upath_info) is not None text = "path_info = %s" path_info_predicate.__text__ = text % path_info weights.append(1 << 3) diff --git a/pyramid/tests/test_config/test_routes.py b/pyramid/tests/test_config/test_routes.py index 140a4aa73..bb47d2d7e 100644 --- a/pyramid/tests/test_config/test_routes.py +++ b/pyramid/tests/test_config/test_routes.py @@ -2,6 +2,7 @@ import unittest from pyramid.tests.test_config import dummyfactory from pyramid.tests.test_config import DummyContext +from pyramid.compat import text_ class RoutesConfiguratorMixinTests(unittest.TestCase): def _makeOne(self, *arg, **kw): @@ -107,10 +108,36 @@ class RoutesConfiguratorMixinTests(unittest.TestCase): route = self._assertRoute(config, 'name', 'path', 1) predicate = route.predicates[0] request = self._makeRequest(config) - request.path_info = '/foo' + request.upath_info = '/foo' self.assertEqual(predicate(None, request), True) request = self._makeRequest(config) - request.path_info = '/' + request.upath_info = '/' + self.assertEqual(predicate(None, request), False) + + def test_add_route_with_path_info_highorder(self): + config = self._makeOne(autocommit=True) + config.add_route('name', 'path', + path_info=text_(b'/La Pe\xc3\xb1a', 'utf-8')) + route = self._assertRoute(config, 'name', 'path', 1) + predicate = route.predicates[0] + request = self._makeRequest(config) + request.upath_info = text_(b'/La Pe\xc3\xb1a', 'utf-8') + self.assertEqual(predicate(None, request), True) + request = self._makeRequest(config) + request.upath_info = text_('/') + self.assertEqual(predicate(None, request), False) + + def test_add_route_with_path_info_regex(self): + config = self._makeOne(autocommit=True) + config.add_route('name', 'path', + path_info=text_(br'/La Pe\w*', 'utf-8')) + route = self._assertRoute(config, 'name', 'path', 1) + predicate = route.predicates[0] + request = self._makeRequest(config) + request.upath_info = text_(b'/La Pe\xc3\xb1a', 'utf-8') + self.assertEqual(predicate(None, request), True) + request = self._makeRequest(config) + request.upath_info = text_('/') self.assertEqual(predicate(None, request), False) def test_add_route_with_request_param(self): diff --git a/pyramid/tests/test_config/test_views.py b/pyramid/tests/test_config/test_views.py index fdf82e7d8..aa4c03db6 100644 --- a/pyramid/tests/test_config/test_views.py +++ b/pyramid/tests/test_config/test_views.py @@ -1283,7 +1283,7 @@ class TestViewsConfigurationMixin(unittest.TestCase): config.add_view(view=view, path_info='/foo', renderer=null_renderer) wrapper = self._getViewCallable(config) request = self._makeRequest(config) - request.path_info = '/foo' + request.upath_info = text_(b'/foo') self.assertEqual(wrapper(None, request), 'OK') def test_add_view_with_path_info_nomatch(self): @@ -1292,7 +1292,7 @@ class TestViewsConfigurationMixin(unittest.TestCase): config.add_view(view=view, path_info='/foo') wrapper = self._getViewCallable(config) request = self._makeRequest(config) - request.path_info = '/' + request.upath_info = text_('/') self._assertNotFound(wrapper, None, request) def test_add_view_with_custom_predicates_match(self): -- cgit v1.2.3