diff options
| author | Chris McDonough <chrism@plope.com> | 2013-09-08 22:52:54 -0400 |
|---|---|---|
| committer | Chris McDonough <chrism@plope.com> | 2013-09-08 22:52:54 -0400 |
| commit | c6601f77f91dc933ca429d1448f4c6b27857b608 (patch) | |
| tree | 2bfcccd8bcfedd224409dc8b49f1f05d3ce0f819 | |
| parent | 95e97113b3fe108a1dbf908ae6716b89e786c91d (diff) | |
| download | pyramid-c6601f77f91dc933ca429d1448f4c6b27857b608.tar.gz pyramid-c6601f77f91dc933ca429d1448f4c6b27857b608.tar.bz2 pyramid-c6601f77f91dc933ca429d1448f4c6b27857b608.zip | |
- The ``renderer_globals_factory`` argument to the
``pyramid.config.Configurator` constructor and its ``setup_registry`` method
has been removed. The ``set_renderer_globals_factory`` method of
``pyramid.config.Configurator`` has also been removed. The (internal)
``pyramid.interfaces.IRendererGlobals`` interface was also removed. These
arguments, methods and interfaces had been deprecated since 1.1. Use a
``BeforeRender`` event subscriber as documented in the "Hooks" chapter of the
Pyramid narrative documentation instead of providing renderer globals values
to the configurator.
| -rw-r--r-- | CHANGES.txt | 10 | ||||
| -rw-r--r-- | docs/api/config.rst | 4 | ||||
| -rw-r--r-- | docs/glossary.rst | 7 | ||||
| -rw-r--r-- | docs/narr/advconfig.rst | 1 | ||||
| -rw-r--r-- | docs/narr/hooks.rst | 66 | ||||
| -rw-r--r-- | docs/narr/introspector.rst | 12 | ||||
| -rw-r--r-- | docs/whatsnew-1.1.rst | 9 | ||||
| -rw-r--r-- | pyramid/config/__init__.py | 23 | ||||
| -rw-r--r-- | pyramid/config/rendering.py | 44 | ||||
| -rw-r--r-- | pyramid/events.py | 5 | ||||
| -rw-r--r-- | pyramid/interfaces.py | 9 | ||||
| -rw-r--r-- | pyramid/renderers.py | 8 | ||||
| -rw-r--r-- | pyramid/tests/test_config/test_init.py | 29 | ||||
| -rw-r--r-- | pyramid/tests/test_config/test_rendering.py | 25 | ||||
| -rw-r--r-- | pyramid/tests/test_renderers.py | 10 |
15 files changed, 20 insertions, 242 deletions
diff --git a/CHANGES.txt b/CHANGES.txt index 6abef1e6b..5cfd5e70d 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -102,6 +102,16 @@ Backwards Incompatibilities ``pyramid.traversal.DefaultRootFactory`` which populated the ``__dict__`` of the factory with the matchdict values for compatibility with BFG 0.9. +- The ``renderer_globals_factory`` argument to the + ``pyramid.config.Configurator` constructor and its ``setup_registry`` method + has been removed. The ``set_renderer_globals_factory`` method of + ``pyramid.config.Configurator`` has also been removed. The (internal) + ``pyramid.interfaces.IRendererGlobals`` interface was also removed. These + arguments, methods and interfaces had been deprecated since 1.1. Use a + ``BeforeRender`` event subscriber as documented in the "Hooks" chapter of the + Pyramid narrative documentation instead of providing renderer globals values + to the configurator. + 1.5a1 (2013-08-30) ================== diff --git a/docs/api/config.rst b/docs/api/config.rst index 1f65be9f1..48dd2f0b9 100644 --- a/docs/api/config.rst +++ b/docs/api/config.rst @@ -52,10 +52,6 @@ .. automethod:: override_asset(to_override, override_with) - :methodcategory:`Setting Renderer Globals` - - .. automethod:: set_renderer_globals_factory(factory) - :methodcategory:`Getting and Adding Settings` .. automethod:: add_settings diff --git a/docs/glossary.rst b/docs/glossary.rst index 8ade889a3..7dc69c7c4 100644 --- a/docs/glossary.rst +++ b/docs/glossary.rst @@ -798,9 +798,8 @@ Glossary :term:`Internationalization`. renderer globals - Values injected as names into a renderer based on application - policy. See :ref:`adding_renderer_globals` for more - information. + Values injected as names into a renderer by a + :class:`pyramid.event.BeforeRender` event. response callback A user-defined callback executed by the :term:`router` at a @@ -1021,4 +1020,4 @@ Glossary add-on A Python :term:`distribution` that uses Pyramid's extensibility to plug into a Pyramid application and provide extra, - configurable services.
\ No newline at end of file + configurable services. diff --git a/docs/narr/advconfig.rst b/docs/narr/advconfig.rst index 1b8e33de3..d3431e39e 100644 --- a/docs/narr/advconfig.rst +++ b/docs/narr/advconfig.rst @@ -302,7 +302,6 @@ These are the methods of the configurator which provide conflict detection: :meth:`~pyramid.config.Configurator.set_view_mapper`, :meth:`~pyramid.config.Configurator.set_authentication_policy`, :meth:`~pyramid.config.Configurator.set_authorization_policy`, -:meth:`~pyramid.config.Configurator.set_renderer_globals_factory`, :meth:`~pyramid.config.Configurator.set_locale_negotiator`, :meth:`~pyramid.config.Configurator.set_default_permission`, :meth:`~pyramid.config.Configurator.add_traverser`, diff --git a/docs/narr/hooks.rst b/docs/narr/hooks.rst index a7dc3e78b..0c450fad7 100644 --- a/docs/narr/hooks.rst +++ b/docs/narr/hooks.rst @@ -372,10 +372,8 @@ that can be used for this purpose. For example: def add_global(event): event['mykey'] = 'foo' -An object of this type is sent as an event just before a :term:`renderer` is -invoked (but *after* the application-level renderer globals factory added via -:class:`~pyramid.config.Configurator.set_renderer_globals_factory`, if any, -has injected its own keys into the renderer globals dictionary). +An object of this type is sent as an event just before a :term:`renderer` +is invoked. If a subscriber attempts to add a key that already exist in the renderer globals dictionary, a :exc:`KeyError` is raised. This limitation is enforced @@ -417,66 +415,6 @@ your view callable, like so: See the API documentation for the :class:`~pyramid.events.BeforeRender` event interface at :class:`pyramid.interfaces.IBeforeRender`. -Another (deprecated) mechanism which allows event subscribers more control -when adding renderer global values exists in :ref:`adding_renderer_globals`. - -.. index:: - single: adding renderer globals - -.. _adding_renderer_globals: - -Adding Renderer Globals (Deprecated) ------------------------------------- - -.. deprecated:: 1.1 - An alternative mechanism which allows event subscribers to add renderer - global values is documented in :ref:`beforerender_event`. - -Whenever :app:`Pyramid` handles a request to perform a rendering (after a -view with a ``renderer=`` configuration attribute is invoked, or when any of -the methods beginning with ``render`` within the :mod:`pyramid.renderers` -module are called), *renderer globals* can be injected into the *system* -values sent to the renderer. By default, no renderer globals are injected, -and the "bare" system values (such as ``request``, ``context``, ``view``, and -``renderer_name``) are the only values present in the system dictionary -passed to every renderer. - -A callback that :app:`Pyramid` will call every time a renderer is invoked can -be added by passing a ``renderer_globals_factory`` argument to the -constructor of the :term:`configurator`. This callback can either be a -callable object or a :term:`dotted Python name` representing such a callable. - -.. code-block:: python - :linenos: - - def renderer_globals_factory(system): - return {'a': 1} - - config = Configurator( - renderer_globals_factory=renderer_globals_factory) - -Such a callback must accept a single positional argument (notionally named -``system``) which will contain the original system values. It must return a -dictionary of values that will be merged into the system dictionary. See -:ref:`renderer_system_values` for description of the values present in the -system dictionary. - -If you're doing imperative configuration, and you'd rather do it after you've -already constructed a :term:`configurator` it can also be registered via the -:meth:`pyramid.config.Configurator.set_renderer_globals_factory` method: - -.. code-block:: python - :linenos: - - from pyramid.config import Configurator - - def renderer_globals_factory(system): - return {'a': 1} - - config = Configurator() - config.set_renderer_globals_factory(renderer_globals_factory) - - .. index:: single: response callback diff --git a/docs/narr/introspector.rst b/docs/narr/introspector.rst index dec22c5b1..3c0a6744f 100644 --- a/docs/narr/introspector.rst +++ b/docs/narr/introspector.rst @@ -232,18 +232,6 @@ introspectables in categories not described here. The factory object (the resolved ``factory`` argument to ``add_renderer``). -``renderer globals factory`` - - There will be one and only one introspectable in the ``renderer globals - factory`` category. It represents a call to - :meth:`pyramid.config.Configurator.set_renderer_globals_factory`; it will - have the following data. - - ``factory`` - - The factory object (the resolved ``factory`` argument to - ``set_renderer_globals_factory``). - ``routes`` Each introspectable in the ``routes`` category represents a call to diff --git a/docs/whatsnew-1.1.rst b/docs/whatsnew-1.1.rst index cc63017df..086c12ca2 100644 --- a/docs/whatsnew-1.1.rst +++ b/docs/whatsnew-1.1.rst @@ -540,11 +540,10 @@ Deprecations and Behavior Differences within a static view returns the index.html properly. See also https://github.com/Pylons/pyramid/issues/67. -- Deprecated the - :meth:`pyramid.config.Configurator.set_renderer_globals_factory` method and - the ``renderer_globals`` Configurator constructor parameter. Users should - convert code using this feature to use a BeforeRender event. See the section - :ref:`beforerender_event` in the Hooks chapter. +- Deprecated the ``pyramid.config.Configurator.set_renderer_globals_factory`` + method and the ``renderer_globals`` Configurator constructor parameter. + Users should convert code using this feature to use a BeforeRender event. See + the section :ref:`beforerender_event` in the Hooks chapter. - In Pyramid 1.0, the :class:`pyramid.events.subscriber` directive behaved contrary to the documentation when passed more than one interface object to diff --git a/pyramid/config/__init__.py b/pyramid/config/__init__.py index f1f24fbc1..0c3a836df 100644 --- a/pyramid/config/__init__.py +++ b/pyramid/config/__init__.py @@ -173,15 +173,6 @@ class Configurator( See :ref:`changing_the_request_factory`. By default it is ``None``, which means use the default request factory. - If ``renderer_globals_factory`` is passed, it should be a :term:`renderer - globals` factory implementation or a :term:`dotted Python name` to the - same. See :ref:`adding_renderer_globals`. By default, it is ``None``, - which means use no renderer globals factory. - - .. deprecated:: 1.1 - Use a BeforeRender event subscriber as per :ref:`beforerender_event` - in place of ``renderer_globals_factory``. - If ``default_permission`` is passed, it should be a :term:`permission` string to be used as the default permission for all view configuration registrations performed against this @@ -273,7 +264,6 @@ class Configurator( debug_logger=None, locale_negotiator=None, request_factory=None, - renderer_globals_factory=None, default_permission=None, session_factory=None, default_view_mapper=None, @@ -304,7 +294,6 @@ class Configurator( debug_logger=debug_logger, locale_negotiator=locale_negotiator, request_factory=request_factory, - renderer_globals_factory=renderer_globals_factory, default_permission=default_permission, session_factory=session_factory, default_view_mapper=default_view_mapper, @@ -320,7 +309,6 @@ class Configurator( debug_logger=None, locale_negotiator=None, request_factory=None, - renderer_globals_factory=None, default_permission=None, session_factory=None, default_view_mapper=None, @@ -410,17 +398,6 @@ class Configurator( if request_factory: self.set_request_factory(request_factory) - if renderer_globals_factory: - warnings.warn( - 'Passing ``renderer_globals_factory`` as a Configurator ' - 'constructor parameter is deprecated as of Pyramid 1.1. ' - 'Use a BeforeRender event subscriber as documented in the ' - '"Hooks" chapter of the Pyramid narrative documentation ' - 'instead', - DeprecationWarning, - 2) - self.set_renderer_globals_factory(renderer_globals_factory, - warn=False) if default_permission: self.set_default_permission(default_permission) diff --git a/pyramid/config/rendering.py b/pyramid/config/rendering.py index a301b9c43..258c5a566 100644 --- a/pyramid/config/rendering.py +++ b/pyramid/config/rendering.py @@ -1,8 +1,5 @@ -import warnings - from pyramid.interfaces import ( IRendererFactory, - IRendererGlobalsFactory, PHASE1_CONFIG, ) @@ -48,44 +45,3 @@ class RenderingConfiguratorMixin(object): self.action((IRendererFactory, name), register, order=PHASE1_CONFIG, introspectables=(intr,)) - @action_method - def set_renderer_globals_factory(self, factory, warn=True): - """ The object passed as ``factory`` should be an callable (or - a :term:`dotted Python name` which refers to an callable) that - will be used by the :app:`Pyramid` rendering machinery as a - renderers global factory (see :ref:`adding_renderer_globals`). - - The ``factory`` callable must accept a single argument named - ``system`` (which will be a dictionary) and it must return a - dictionary. When an application uses a renderer, the - factory's return dictionary will be merged into the ``system`` - dictionary, and therefore will be made available to the code - which uses the renderer. - - .. deprecated:: 1.1 - Use a BeforeRender event subscriber as documented in the - :ref:`hooks_chapter` chapter instead. - - .. note:: - - Using the ``renderer_globals_factory`` argument - to the :class:`pyramid.config.Configurator` constructor - can be used to achieve the same purpose. - """ - if warn: - warnings.warn( - 'Calling the ``set_renderer_globals`` method of a Configurator ' - 'is deprecated as of Pyramid 1.1. Use a BeforeRender event ' - 'subscriber as documented in the "Hooks" chapter of the ' - 'Pyramid narrative documentation instead', - DeprecationWarning, - 3) - - factory = self.maybe_dotted(factory) - def register(): - self.registry.registerUtility(factory, IRendererGlobalsFactory) - intr = self.introspectable('renderer globals factory', None, - self.object_description(factory), - 'renderer globals factory') - intr['factory'] = factory - self.action(IRendererGlobalsFactory, register) diff --git a/pyramid/events.py b/pyramid/events.py index 31af8e1fc..ca10e2893 100644 --- a/pyramid/events.py +++ b/pyramid/events.py @@ -192,10 +192,7 @@ class BeforeRender(dict): event['mykey'] = 'foo' An object of this type is sent as an event just before a :term:`renderer` - is invoked (but *after* the -- deprecated -- application-level renderer - globals factory added via - :class:`pyramid.config.Configurator.set_renderer_globals_factory`, if - any, has injected its own keys into the renderer globals dictionary). + is invoked. If a subscriber adds a key via ``__setitem__`` that already exists in the renderer globals dictionary, it will overwrite the older value there. diff --git a/pyramid/interfaces.py b/pyramid/interfaces.py index 1d5688195..85b2227b4 100644 --- a/pyramid/interfaces.py +++ b/pyramid/interfaces.py @@ -616,15 +616,6 @@ class IRendererFactory(Interface): """ Return an object that implements ``IRenderer``. ``info`` is an object that implement ``IRendererInfo``. """ -class IRendererGlobalsFactory(Interface): - def __call__(system_values): - """ Return a dictionary of global renderer values (aka - top-level template names). The ``system_values`` value passed - in will be a dictionary that includes at least a ``request`` - key, indicating the current request, and the value - ``renderer_name``, which will be the name of the renderer in - use.""" - class IViewPermission(Interface): def __call__(context, request): """ Return True if the permission allows, return False if it denies. """ diff --git a/pyramid/renderers.py b/pyramid/renderers.py index 6f088a54f..d8542decc 100644 --- a/pyramid/renderers.py +++ b/pyramid/renderers.py @@ -9,7 +9,6 @@ from zope.interface.registry import Components from pyramid.interfaces import ( IJSONAdapter, - IRendererGlobalsFactory, IRendererFactory, IResponseFactory, IRendererInfo, @@ -425,13 +424,6 @@ class RendererHelper(object): system_values = BeforeRender(system_values, value) registry = self.registry - globals_factory = registry.queryUtility(IRendererGlobalsFactory) - - if globals_factory is not None: - renderer_globals = globals_factory(system_values) - if renderer_globals: - system_values.update(renderer_globals) - registry.notify(system_values) result = renderer(value, system_values) diff --git a/pyramid/tests/test_config/test_init.py b/pyramid/tests/test_config/test_init.py index 14054421e..a0333b66d 100644 --- a/pyramid/tests/test_config/test_init.py +++ b/pyramid/tests/test_config/test_init.py @@ -550,35 +550,6 @@ class ConfiguratorTests(unittest.TestCase): utility = reg.getUtility(IRequestFactory) self.assertEqual(utility, pyramid.tests.test_config) - def test_setup_registry_renderer_globals_factory(self): - from pyramid.registry import Registry - from pyramid.interfaces import IRendererGlobalsFactory - reg = Registry() - config = self._makeOne(reg) - factory = object() - with warnings.catch_warnings(): - warnings.filterwarnings('ignore') - config.setup_registry(renderer_globals_factory=factory) - self.assertEqual(reg.queryUtility(IRendererGlobalsFactory), None) - config.commit() - utility = reg.getUtility(IRendererGlobalsFactory) - self.assertEqual(utility, factory) - - def test_setup_registry_renderer_globals_factory_dottedname(self): - from pyramid.registry import Registry - from pyramid.interfaces import IRendererGlobalsFactory - reg = Registry() - config = self._makeOne(reg) - import pyramid.tests.test_config - with warnings.catch_warnings(): - warnings.filterwarnings('ignore') - config.setup_registry( - renderer_globals_factory='pyramid.tests.test_config') - self.assertEqual(reg.queryUtility(IRendererGlobalsFactory), None) - config.commit() - utility = reg.getUtility(IRendererGlobalsFactory) - self.assertEqual(utility, pyramid.tests.test_config) - def test_setup_registry_alternate_renderers(self): from pyramid.registry import Registry from pyramid.interfaces import IRendererFactory diff --git a/pyramid/tests/test_config/test_rendering.py b/pyramid/tests/test_config/test_rendering.py index e6ee9ad70..2c3730775 100644 --- a/pyramid/tests/test_config/test_rendering.py +++ b/pyramid/tests/test_config/test_rendering.py @@ -1,7 +1,4 @@ import unittest -import warnings - -from pyramid.tests.test_config import dummyfactory class TestRenderingConfiguratorMixin(unittest.TestCase): def _makeOne(self, *arg, **kw): @@ -9,28 +6,6 @@ class TestRenderingConfiguratorMixin(unittest.TestCase): config = Configurator(*arg, **kw) return config - def test_set_renderer_globals_factory(self): - from pyramid.interfaces import IRendererGlobalsFactory - config = self._makeOne(autocommit=True) - factory = object() - with warnings.catch_warnings(): - warnings.filterwarnings('ignore') - config.set_renderer_globals_factory(factory) - self.assertEqual( - config.registry.getUtility(IRendererGlobalsFactory), - factory) - - def test_set_renderer_globals_factory_dottedname(self): - from pyramid.interfaces import IRendererGlobalsFactory - config = self._makeOne(autocommit=True) - with warnings.catch_warnings(): - warnings.filterwarnings('ignore') - config.set_renderer_globals_factory( - 'pyramid.tests.test_config.dummyfactory') - self.assertEqual( - config.registry.getUtility(IRendererGlobalsFactory), - dummyfactory) - def test_add_renderer(self): from pyramid.interfaces import IRendererFactory config = self._makeOne(autocommit=True) diff --git a/pyramid/tests/test_renderers.py b/pyramid/tests/test_renderers.py index 0b67462bb..f6b9d2b0d 100644 --- a/pyramid/tests/test_renderers.py +++ b/pyramid/tests/test_renderers.py @@ -255,16 +255,6 @@ class TestRendererHelper(unittest.TestCase): self.assertEqual(result[0], 'values') self.assertEqual(result[1], system) - def test_render_renderer_globals_factory_active(self): - self._registerRendererFactory() - from pyramid.interfaces import IRendererGlobalsFactory - def rg(system): - return {'a':1} - self.config.registry.registerUtility(rg, IRendererGlobalsFactory) - helper = self._makeOne('loo.foo') - result = helper.render('values', None) - self.assertEqual(result[1]['a'], 1) - def test__make_response_request_is_None(self): request = None helper = self._makeOne('loo.foo') |
