Skip to content
Browse files

- 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``.
  • Loading branch information...
1 parent 780bbf9 commit fdf30b3bb6f47d93d2f255a09e75be0c33d54789 @mcdonc mcdonc committed Sep 8, 2013
View
10 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)
==================
View
7 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
View
158 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 @@ def add_route(self,
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 @@ def add_route(self,
.. 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 @@ def register_connect():
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 @@ def get_routes_mapper(self):
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)
-
View
20 pyramid/config/views.py
@@ -1910,27 +1910,16 @@ def add(self, config, name, spec, **extra):
# 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 @@ def add(self, config, name, spec, **extra):
permission=permission,
context=context,
renderer=renderer,
- attr=attr
)
def register():
View
199 pyramid/tests/test_config/test_init.py
@@ -1182,205 +1182,6 @@ def foo(config): pass
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):
View
35 pyramid/tests/test_config/test_views.py
@@ -3777,42 +3777,20 @@ def test_add_viewname_with_permission(self):
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()
inst.add(config, 'view', 'anotherpackage:path', cache_max_age=1,
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 @@ def test_add_viewname_with_renderer(self):
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

0 comments on commit fdf30b3

Please sign in to comment.
Something went wrong with that request. Please try again.