diff options
| author | Chris McDonough <chrism@plope.com> | 2011-07-13 01:54:03 -0400 |
|---|---|---|
| committer | Chris McDonough <chrism@plope.com> | 2011-07-13 01:54:03 -0400 |
| commit | 873d9be3a787793caeb66223d2bb68dbc1fc396e (patch) | |
| tree | 44e9e3a5e4b5bcdfb0edca8f2c785e7576a35360 | |
| parent | d05117e9655e3619e66bfef86f40043fbcc61829 (diff) | |
| download | pyramid-873d9be3a787793caeb66223d2bb68dbc1fc396e.tar.gz pyramid-873d9be3a787793caeb66223d2bb68dbc1fc396e.tar.bz2 pyramid-873d9be3a787793caeb66223d2bb68dbc1fc396e.zip | |
- Views associated with routes with spaces in the route name may not have
been looked up correctly when using Pyramid with ``zope.interface`` 3.6.4
and better.
Closes #232.
| -rw-r--r-- | CHANGES.txt | 4 | ||||
| -rw-r--r-- | pyramid/request.py | 15 | ||||
| -rw-r--r-- | pyramid/tests/test_request.py | 9 |
3 files changed, 25 insertions, 3 deletions
diff --git a/CHANGES.txt b/CHANGES.txt index 21bea6572..71491cb9b 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -49,6 +49,10 @@ Bug Fixes exception view will be working with a request.response that has not been touched by any code prior to the exception. +- Views associated with routes with spaces in the route name may not have + been looked up correctly when using Pyramid with ``zope.interface`` 3.6.4 + and better. + Documentation ------------- diff --git a/pyramid/request.py b/pyramid/request.py index 1bf044b69..8df204681 100644 --- a/pyramid/request.py +++ b/pyramid/request.py @@ -496,10 +496,19 @@ class Request(BaseRequest, DeprecatedRequestMethods): def route_request_iface(name, bases=()): - iface = InterfaceClass('%s_IRequest' % name, bases=bases) + # zope.interface treats the __name__ as the __doc__ and changes __name__ + # to None for interfaces that contain spaces if you do not pass a + # nonempty __doc__ (insane); see + # zope.interface.interface.Element.__init__ and + # https://github.com/Pylons/pyramid/issues/232; as a result, always pass + # __doc__ to the InterfaceClass constructor. + iface = InterfaceClass('%s_IRequest' % name, bases=bases, + __doc__="route_request_iface-generated interface") # for exception view lookups - iface.combined = InterfaceClass('%s_combined_IRequest' % name, - bases=(iface, IRequest)) + iface.combined = InterfaceClass( + '%s_combined_IRequest' % name, + bases=(iface, IRequest), + __doc__ = 'route_request_iface-generated combined interface') return iface def add_global_response_headers(request, headerlist): diff --git a/pyramid/tests/test_request.py b/pyramid/tests/test_request.py index 74bc25359..066aa9207 100644 --- a/pyramid/tests/test_request.py +++ b/pyramid/tests/test_request.py @@ -424,6 +424,15 @@ class Test_route_request_iface(unittest.TestCase): self.assertTrue(hasattr(iface, 'combined')) self.assertEqual(iface.combined.__name__, 'routename_combined_IRequest') + def test_it_routename_with_spaces(self): + # see https://github.com/Pylons/pyramid/issues/232 + iface = self._callFUT('routename with spaces') + self.assertEqual(iface.__name__, 'routename with spaces_IRequest') + self.assertTrue(hasattr(iface, 'combined')) + self.assertEqual(iface.combined.__name__, + 'routename with spaces_combined_IRequest') + + class Test_add_global_response_headers(unittest.TestCase): def _callFUT(self, request, headerlist): from pyramid.request import add_global_response_headers |
