Chris McDonough
2012-01-07 a5d9943f643f9d4fd7a25f1a9722bf385430b768
- 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.
4 files modified
45 ■■■■ changed files
CHANGES.txt 8 ●●●●● patch | view | raw | blame | history
pyramid/config/util.py 2 ●●● patch | view | raw | blame | history
pyramid/tests/test_config/test_routes.py 31 ●●●●● patch | view | raw | blame | history
pyramid/tests/test_config/test_views.py 4 ●●●● patch | view | raw | blame | history
CHANGES.txt
@@ -8,6 +8,14 @@
  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)
==================
pyramid/config/util.py
@@ -145,7 +145,7 @@
        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)
pyramid/tests/test_config/test_routes.py
@@ -2,6 +2,7 @@
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 @@
        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):
pyramid/tests/test_config/test_views.py
@@ -1283,7 +1283,7 @@
        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 @@
        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):