diff options
| -rw-r--r-- | CHANGES.txt | 5 | ||||
| -rw-r--r-- | pyramid/config/views.py | 2 | ||||
| -rw-r--r-- | pyramid/tests/test_config/test_views.py | 25 |
3 files changed, 27 insertions, 5 deletions
diff --git a/CHANGES.txt b/CHANGES.txt index 369e9d74d..c414ab74c 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -37,6 +37,11 @@ Bug Fixes ``__doc__`` attributes. See https://github.com/Pylons/pyramid/issues/621 and https://github.com/Pylons/pyramid/pull/647. +- Forward-port from 1.3 branch: when registering multiple views with an + ``accept`` predicate in a Pyramid application runing under Python 3, you + might have received a ``TypeError: unorderable types: function() < + function()`` exception. + Features -------- diff --git a/pyramid/config/views.py b/pyramid/config/views.py index 19e4acbcb..36896a17e 100644 --- a/pyramid/config/views.py +++ b/pyramid/config/views.py @@ -573,7 +573,7 @@ class MultiView(object): return else: subset.append((order, view, phash)) - subset.sort() + subset.sort(key=operator.itemgetter(0)) accepts = set(self.accepts) accepts.add(accept) self.accepts = list(accepts) # dedupe diff --git a/pyramid/tests/test_config/test_views.py b/pyramid/tests/test_config/test_views.py index 72a0d8ebd..575d8c738 100644 --- a/pyramid/tests/test_config/test_views.py +++ b/pyramid/tests/test_config/test_views.py @@ -2140,11 +2140,28 @@ class TestMultiView(unittest.TestCase): def test_add_with_phash_override_accept(self): mv = self._makeOne() - mv.add('view2', 100, accept='text/html', phash='abc') - mv.add('view3', 100, accept='text/html', phash='abc') - mv.add('view4', 99, accept='text/html', phash='def') + def view1(): pass + def view2(): pass + def view3(): pass + mv.add(view1, 100, accept='text/html', phash='abc') + mv.add(view2, 100, accept='text/html', phash='abc') + mv.add(view3, 99, accept='text/html', phash='def') self.assertEqual(mv.media_views['text/html'], - [(99, 'view4', 'def'), (100, 'view3', 'abc')]) + [(99, view3, 'def'), (100, view2, 'abc')]) + + def test_add_with_phash_override_accept2(self): + mv = self._makeOne() + def view1(): pass + def view2(): pass + def view3(): pass + mv.add(view1, 100, accept='text/html', phash='abc') + mv.add(view2, 100, accept='text/html', phash='def') + mv.add(view3, 99, accept='text/html', phash='ghi') + self.assertEqual(mv.media_views['text/html'], + [(99, view3, 'ghi'), + (100, view1, 'abc'), + (100, view2, 'def')] + ) def test_multiple_with_functions_as_views(self): # this failed on py3 at one point, because functions aren't orderable |
