diff options
| author | Chris McDonough <chrism@plope.com> | 2013-09-08 21:12:10 -0400 |
|---|---|---|
| committer | Chris McDonough <chrism@plope.com> | 2013-09-08 21:12:10 -0400 |
| commit | fdf30b3bb6f47d93d2f255a09e75be0c33d54789 (patch) | |
| tree | b67de9c251bdd232e03fbb9bb0ac44a2c76a91d3 | |
| parent | 780bbf9998fd805df55499ef4a78f41cbf99c7de (diff) | |
| download | pyramid-fdf30b3bb6f47d93d2f255a09e75be0c33d54789.tar.gz pyramid-fdf30b3bb6f47d93d2f255a09e75be0c33d54789.tar.bz2 pyramid-fdf30b3bb6f47d93d2f255a09e75be0c33d54789.zip | |
- Removed the ability to pass the following arguments to
``pyramid.config.Configurator.add_route``: `view``, ``view_context``.
``view_for``, ``view_permission``, ``view_renderer``, and ``view_attr``.
Using these arguments had been deprecated since Pyramid 1.1. Instead of
passing view-related arguments to ``add_route``, use a separate call to
``pyramid.config.Configurator.add_view`` to associate a view with a route
using its ``route_name`` argument. Note that this impacts the
``pyramid.config.Configurator.add_static_view`` function too, because it
delegates to ``add_route``.
| -rw-r--r-- | CHANGES.txt | 10 | ||||
| -rw-r--r-- | docs/narr/urldispatch.rst | 7 | ||||
| -rw-r--r-- | pyramid/config/routes.py | 158 | ||||
| -rw-r--r-- | pyramid/config/views.py | 20 | ||||
| -rw-r--r-- | pyramid/tests/test_config/test_init.py | 199 | ||||
| -rw-r--r-- | pyramid/tests/test_config/test_views.py | 35 |
6 files changed, 17 insertions, 412 deletions
diff --git a/CHANGES.txt b/CHANGES.txt index 989d1bca1..69547ad46 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -81,6 +81,16 @@ Backwards Incompatibilities since Pyramid 1.1. Use the ``pyramid.request.Request.is_response`` method instead. +- Removed the ability to pass the following arguments to + ``pyramid.config.Configurator.add_route``: `view``, ``view_context``. + ``view_for``, ``view_permission``, ``view_renderer``, and ``view_attr``. + Using these arguments had been deprecated since Pyramid 1.1. Instead of + passing view-related arguments to ``add_route``, use a separate call to + ``pyramid.config.Configurator.add_view`` to associate a view with a route + using its ``route_name`` argument. Note that this impacts the + ``pyramid.config.Configurator.add_static_view`` function too, because it + delegates to ``add_route``. + 1.5a1 (2013-08-30) ================== diff --git a/docs/narr/urldispatch.rst b/docs/narr/urldispatch.rst index 62eb89348..61849c3c0 100644 --- a/docs/narr/urldispatch.rst +++ b/docs/narr/urldispatch.rst @@ -399,13 +399,6 @@ process. Examples of route predicate arguments are ``pattern``, ``xhr``, and Other arguments are ``name`` and ``factory``. These arguments represent neither predicates nor view configuration information. -.. warning:: - - Some arguments are view-configuration related arguments, such as - ``view_renderer``. These only have an effect when the route configuration - names a ``view`` and these arguments have been deprecated as of - :app:`Pyramid` 1.1. - .. index:: single: route matching diff --git a/pyramid/config/routes.py b/pyramid/config/routes.py index 14dd87d0f..c31bd7195 100644 --- a/pyramid/config/routes.py +++ b/pyramid/config/routes.py @@ -1,5 +1,3 @@ -import warnings - from pyramid.compat import urlparse from pyramid.interfaces import ( IRequest, @@ -25,8 +23,6 @@ class RoutesConfiguratorMixin(object): def add_route(self, name, pattern=None, - view=None, - view_for=None, permission=None, factory=None, for_=None, @@ -38,11 +34,7 @@ class RoutesConfiguratorMixin(object): request_param=None, traverse=None, custom_predicates=(), - view_permission=None, renderer=None, - view_renderer=None, - view_context=None, - view_attr=None, use_global_views=False, path=None, pregenerator=None, @@ -284,97 +276,6 @@ class RoutesConfiguratorMixin(object): .. versionadded:: 1.4 - View-Related Arguments - - .. warning:: - - The arguments described below have been deprecated as of - :app:`Pyramid` 1.1. *Do not use these for new development; they - should only be used to support older code bases which depend upon - them.* Use a separate call to - :meth:`pyramid.config.Configurator.add_view` to associate a view - with a route using the ``route_name`` argument. - - view - - .. deprecated:: 1.1 - - A Python object or :term:`dotted Python name` to the same - object that will be used as a view callable when this route - matches. e.g. ``mypackage.views.my_view``. - - view_context - - .. deprecated:: 1.1 - - A class or an :term:`interface` or :term:`dotted Python - name` to the same object which the :term:`context` of the - view should match for the view named by the route to be - used. This argument is only useful if the ``view`` - attribute is used. If this attribute is not specified, the - default (``None``) will be used. - - If the ``view`` argument is not provided, this argument has - no effect. - - This attribute can also be spelled as ``for_`` or ``view_for``. - - view_permission - - .. deprecated:: 1.1 - - The permission name required to invoke the view associated - with this route. e.g. ``edit``. (see - :ref:`using_security_with_urldispatch` for more information - about permissions). - - If the ``view`` attribute is not provided, this argument has - no effect. - - This argument can also be spelled as ``permission``. - - view_renderer - - .. deprecated:: 1.1 - - This is either a single string term (e.g. ``json``) or a - string implying a path or :term:`asset specification` - (e.g. ``templates/views.pt``). If the renderer value is a - single term (does not contain a dot ``.``), the specified - term will be used to look up a renderer implementation, and - that renderer implementation will be used to construct a - response from the view return value. If the renderer term - contains a dot (``.``), the specified term will be treated - as a path, and the filename extension of the last element in - the path will be used to look up the renderer - implementation, which will be passed the full path. The - renderer implementation will be used to construct a response - from the view return value. See - :ref:`views_which_use_a_renderer` for more information. - - If the ``view`` argument is not provided, this argument has - no effect. - - This argument can also be spelled as ``renderer``. - - view_attr - - .. deprecated:: 1.1 - - The view machinery defaults to using the ``__call__`` method - of the view callable (or the function itself, if the view - callable is a function) to obtain a response dictionary. - The ``attr`` value allows you to vary the method attribute - used to obtain the response. For example, if your view was - a class, and the class has a method named ``index`` and you - wanted to use this method instead of the class' ``__call__`` - method to return the response, you'd say ``attr="index"`` in - the view configuration for the view. This is - most useful when the view definition is a class. - - If the ``view`` argument is not provided, this argument has no - effect. - """ # these are route predicates; if they do not match, the next route # in the routelist will be tried @@ -501,19 +402,6 @@ class RoutesConfiguratorMixin(object): self.action(('route', name), register_route_request_iface, order=PHASE2_CONFIG, introspectables=introspectables) - # deprecated adding views from add_route; must come after - # route registration for purposes of autocommit ordering - if any([view, view_context, view_permission, view_renderer, - view_for, for_, permission, renderer, view_attr]): - self._add_view_from_route( - route_name=name, - view=view, - permission=view_permission or permission, - context=view_context or view_for or for_, - renderer=view_renderer or renderer, - attr=view_attr, - ) - @action_method def add_route_predicate(self, name, factory, weighs_more_than=None, weighs_less_than=None): @@ -564,49 +452,3 @@ class RoutesConfiguratorMixin(object): self.registry.registerUtility(mapper, IRoutesMapper) return mapper - def _add_view_from_route(self, - route_name, - view, - context, - permission, - renderer, - attr, - ): - if view: - self.add_view( - permission=permission, - context=context, - view=view, - name='', - route_name=route_name, - renderer=renderer, - attr=attr, - ) - else: - # prevent mistakes due to misunderstanding of how hybrid calls to - # add_route and add_view interact - if attr: - raise ConfigurationError( - 'view_attr argument not permitted without view ' - 'argument') - if context: - raise ConfigurationError( - 'view_context argument not permitted without view ' - 'argument') - if permission: - raise ConfigurationError( - 'view_permission argument not permitted without view ' - 'argument') - if renderer: - raise ConfigurationError( - 'view_renderer argument not permitted without ' - 'view argument') - - warnings.warn( - 'Passing view-related arguments to add_route() is deprecated as of ' - 'Pyramid 1.1. Use add_view() to associate a view with a route ' - 'instead. See "Deprecations" in "What\'s New in Pyramid 1.1" ' - 'within the general Pyramid documentation for further details.', - DeprecationWarning, - 4) - diff --git a/pyramid/config/views.py b/pyramid/config/views.py index 243c017fa..a4b681347 100644 --- a/pyramid/config/views.py +++ b/pyramid/config/views.py @@ -1910,27 +1910,16 @@ class StaticURLInfo(object): # Mutate extra to allow factory, etc to be passed through here. # Treat permission specially because we'd like to default to - # permissiveness (see docs of config.add_static_view). We need - # to deal with both ``view_permission`` and ``permission`` - # because ``permission`` is used in the docs for add_static_view, - # but ``add_route`` prefers ``view_permission`` - permission = extra.pop('view_permission', None) - if permission is None: - permission = extra.pop('permission', None) + # permissiveness (see docs of config.add_static_view). + permission = extra.pop('permission', None) if permission is None: permission = NO_PERMISSION_REQUIRED - context = extra.pop('view_context', None) - if context is None: - context = extra.pop('view_for', None) + context = extra.pop('context', None) if context is None: context = extra.pop('for_', None) - renderer = extra.pop('view_renderer', None) - if renderer is None: - renderer = extra.pop('renderer', None) - - attr = extra.pop('view_attr', None) + renderer = extra.pop('renderer', None) # register a route using the computed view, permission, and # pattern, plus any extras passed to us via add_static_view @@ -1946,7 +1935,6 @@ class StaticURLInfo(object): permission=permission, context=context, renderer=renderer, - attr=attr ) def register(): diff --git a/pyramid/tests/test_config/test_init.py b/pyramid/tests/test_config/test_init.py index a7ef65fe8..14054421e 100644 --- a/pyramid/tests/test_config/test_init.py +++ b/pyramid/tests/test_config/test_init.py @@ -1182,205 +1182,6 @@ pyramid.tests.test_config.dummy_include2""", foo_meth = config.foo self.assertTrue(getattr(foo_meth, im_func) is foo) -class TestConfiguratorDeprecatedFeatures(unittest.TestCase): - - def setUp(self): - self.warnings = warnings.catch_warnings() - self.warnings.__enter__() - warnings.filterwarnings('ignore') - - def tearDown(self): - self.warnings.__exit__(None, None, None) - - def _makeOne(self, *arg, **kw): - from pyramid.config import Configurator - config = Configurator(*arg, **kw) - config.registry._dont_resolve_responses = True - return config - - def _getRouteRequestIface(self, config, name): - from pyramid.interfaces import IRouteRequest - iface = config.registry.getUtility(IRouteRequest, name) - return iface - - def _getViewCallable(self, config, ctx_iface=None, request_iface=None, - name='', exception_view=False): - from zope.interface import Interface - from pyramid.interfaces import IView - from pyramid.interfaces import IViewClassifier - from pyramid.interfaces import IExceptionViewClassifier - if exception_view: - classifier = IExceptionViewClassifier - else: - classifier = IViewClassifier - if ctx_iface is None: - ctx_iface = Interface - return config.registry.adapters.lookup( - (classifier, request_iface, ctx_iface), IView, name=name, - default=None) - - def _assertRoute(self, config, name, path, num_predicates=0): - from pyramid.interfaces import IRoutesMapper - mapper = config.registry.getUtility(IRoutesMapper) - routes = mapper.get_routes() - route = routes[0] - self.assertEqual(len(routes), 1) - self.assertEqual(route.name, name) - self.assertEqual(route.path, path) - self.assertEqual(len(routes[0].predicates), num_predicates) - return route - - def _makeRequest(self, config): - request = DummyRequest() - request.registry = config.registry - return request - - def test_add_route_with_view(self): - from pyramid.renderers import null_renderer - config = self._makeOne(autocommit=True) - view = lambda *arg: 'OK' - config.add_route('name', 'path', view=view, view_renderer=null_renderer) - request_type = self._getRouteRequestIface(config, 'name') - wrapper = self._getViewCallable(config, None, request_type) - self.assertEqual(wrapper(None, None), 'OK') - self._assertRoute(config, 'name', 'path') - - def test_add_route_with_view_context(self): - from pyramid.renderers import null_renderer - config = self._makeOne(autocommit=True) - view = lambda *arg: 'OK' - config.add_route('name', 'path', view=view, view_context=IDummy, - view_renderer=null_renderer) - request_type = self._getRouteRequestIface(config, 'name') - wrapper = self._getViewCallable(config, IDummy, request_type) - self.assertEqual(wrapper(None, None), 'OK') - self._assertRoute(config, 'name', 'path') - wrapper = self._getViewCallable(config, IOther, request_type) - self.assertEqual(wrapper, None) - - def test_add_route_with_view_exception(self): - from pyramid.renderers import null_renderer - from zope.interface import implementedBy - config = self._makeOne(autocommit=True) - view = lambda *arg: 'OK' - config.add_route('name', 'path', view=view, view_context=RuntimeError, - view_renderer=null_renderer) - request_type = self._getRouteRequestIface(config, 'name') - wrapper = self._getViewCallable( - config, ctx_iface=implementedBy(RuntimeError), - request_iface=request_type, exception_view=True) - self.assertEqual(wrapper(None, None), 'OK') - self._assertRoute(config, 'name', 'path') - wrapper = self._getViewCallable( - config, ctx_iface=IOther, - request_iface=request_type, exception_view=True) - self.assertEqual(wrapper, None) - - def test_add_route_with_view_for(self): - from pyramid.renderers import null_renderer - config = self._makeOne(autocommit=True) - view = lambda *arg: 'OK' - config.add_route('name', 'path', view=view, view_for=IDummy, - view_renderer=null_renderer) - request_type = self._getRouteRequestIface(config, 'name') - wrapper = self._getViewCallable(config, IDummy, request_type) - self.assertEqual(wrapper(None, None), 'OK') - self._assertRoute(config, 'name', 'path') - wrapper = self._getViewCallable(config, IOther, request_type) - self.assertEqual(wrapper, None) - - def test_add_route_with_for_(self): - from pyramid.renderers import null_renderer - config = self._makeOne(autocommit=True) - view = lambda *arg: 'OK' - config.add_route('name', 'path', view=view, for_=IDummy, - view_renderer=null_renderer) - request_type = self._getRouteRequestIface(config, 'name') - wrapper = self._getViewCallable(config, IDummy, request_type) - self.assertEqual(wrapper(None, None), 'OK') - self._assertRoute(config, 'name', 'path') - wrapper = self._getViewCallable(config, IOther, request_type) - self.assertEqual(wrapper, None) - - def test_add_route_with_view_renderer(self): - config = self._makeOne(autocommit=True) - view = lambda *arg: 'OK' - config.add_route('name', 'path', view=view, - view_renderer='json') - request_type = self._getRouteRequestIface(config, 'name') - wrapper = self._getViewCallable(config, None, request_type) - self._assertRoute(config, 'name', 'path') - self.assertEqual(wrapper(None, None).body, b'"OK"') - - def test_add_route_with_view_attr(self): - from pyramid.renderers import null_renderer - config = self._makeOne(autocommit=True) - class View(object): - def __init__(self, context, request): - pass - def alt(self): - return 'OK' - config.add_route('name', 'path', view=View, view_attr='alt', - view_renderer=null_renderer) - request_type = self._getRouteRequestIface(config, 'name') - wrapper = self._getViewCallable(config, None, request_type) - self._assertRoute(config, 'name', 'path') - request = self._makeRequest(config) - self.assertEqual(wrapper(None, request), 'OK') - - def test_add_route_with_view_renderer_alias(self): - config = self._makeOne(autocommit=True) - view = lambda *arg: 'OK' - config.add_route('name', 'path', view=view, - renderer='json') - request_type = self._getRouteRequestIface(config, 'name') - wrapper = self._getViewCallable(config, None, request_type) - self._assertRoute(config, 'name', 'path') - self.assertEqual(wrapper(None, None).body, b'"OK"') - - def test_add_route_with_view_permission(self): - from pyramid.interfaces import IAuthenticationPolicy - from pyramid.interfaces import IAuthorizationPolicy - config = self._makeOne(autocommit=True) - policy = lambda *arg: None - config.registry.registerUtility(policy, IAuthenticationPolicy) - config.registry.registerUtility(policy, IAuthorizationPolicy) - view = lambda *arg: 'OK' - config.add_route('name', 'path', view=view, view_permission='edit') - request_type = self._getRouteRequestIface(config, 'name') - wrapper = self._getViewCallable(config, None, request_type) - self._assertRoute(config, 'name', 'path') - self.assertTrue(hasattr(wrapper, '__call_permissive__')) - - def test_add_route_with_view_permission_alias(self): - from pyramid.interfaces import IAuthenticationPolicy - from pyramid.interfaces import IAuthorizationPolicy - config = self._makeOne(autocommit=True) - policy = lambda *arg: None - config.registry.registerUtility(policy, IAuthenticationPolicy) - config.registry.registerUtility(policy, IAuthorizationPolicy) - view = lambda *arg: 'OK' - config.add_route('name', 'path', view=view, permission='edit') - request_type = self._getRouteRequestIface(config, 'name') - wrapper = self._getViewCallable(config, None, request_type) - self._assertRoute(config, 'name', 'path') - self.assertTrue(hasattr(wrapper, '__call_permissive__')) - - def test_conflict_route_with_view(self): - config = self._makeOne() - def view1(request): pass - def view2(request): pass - config.add_route('a', '/a', view=view1) - config.add_route('a', '/a', view=view2) - try: - config.commit() - except ConfigurationConflictError as why: - c1, c2 = _conflictFunctions(why) - self.assertEqual(c1, 'test_conflict_route_with_view') - self.assertEqual(c2, 'test_conflict_route_with_view') - else: # pragma: no cover - raise AssertionError - class TestConfigurator_add_directive(unittest.TestCase): def setUp(self): diff --git a/pyramid/tests/test_config/test_views.py b/pyramid/tests/test_config/test_views.py index 618ac2bf4..848642aee 100644 --- a/pyramid/tests/test_config/test_views.py +++ b/pyramid/tests/test_config/test_views.py @@ -3777,27 +3777,13 @@ class TestStaticURLInfo(unittest.TestCase): permission='abc') self.assertEqual(config.view_kw['permission'], 'abc') - def test_add_viewname_with_view_permission(self): + def test_add_viewname_with_context(self): config = self._makeConfig() inst = self._makeOne() inst.add(config, 'view', 'anotherpackage:path', cache_max_age=1, - view_permission='abc') - self.assertEqual(config.view_kw['permission'], 'abc') - - def test_add_viewname_with_view_context(self): - config = self._makeConfig() - inst = self._makeOne() - inst.add(config, 'view', 'anotherpackage:path', cache_max_age=1, - view_context=DummyContext) + context=DummyContext) self.assertEqual(config.view_kw['context'], DummyContext) - - def test_add_viewname_with_view_for(self): - config = self._makeConfig() - inst = self._makeOne() - inst.add(config, 'view', 'anotherpackage:path', cache_max_age=1, - view_for=DummyContext) - self.assertEqual(config.view_kw['context'], DummyContext) - + def test_add_viewname_with_for_(self): config = self._makeConfig() inst = self._makeOne() @@ -3805,14 +3791,6 @@ class TestStaticURLInfo(unittest.TestCase): for_=DummyContext) self.assertEqual(config.view_kw['context'], DummyContext) - def test_add_viewname_with_view_renderer(self): - config = self._makeConfig() - inst = self._makeOne() - inst.add(config, 'view', 'anotherpackage:path', cache_max_age=1, - view_renderer='mypackage:templates/index.pt') - self.assertEqual(config.view_kw['renderer'], - 'mypackage:templates/index.pt') - def test_add_viewname_with_renderer(self): config = self._makeConfig() inst = self._makeOne() @@ -3821,13 +3799,6 @@ class TestStaticURLInfo(unittest.TestCase): self.assertEqual(config.view_kw['renderer'], 'mypackage:templates/index.pt') - def test_add_viewname_with_view_attr(self): - config = self._makeConfig() - inst = self._makeOne() - inst.add(config, 'view', 'anotherpackage:path', cache_max_age=1, - view_attr='attr') - self.assertEqual(config.view_kw['attr'], 'attr') - class Test_view_description(unittest.TestCase): def _callFUT(self, view): from pyramid.config.views import view_description |
