Permalink
Browse files

- Add a deprecation warning for non-API function

  ``pyramid.renderers.renderer_from_name`` which has seen use in the wild.

- Add a ``clone`` method to ``pyramid.renderers.RendererHelper`` for use by
  the ``pyramid.view.view_config`` decorator.
  • Loading branch information...
1 parent 0eaa60f commit 73c0aee5571bbdd7273033eda3a798d5597a76af @mcdonc mcdonc committed Jul 21, 2011
Showing with 55 additions and 8 deletions.
  1. +6 −0 CHANGES.txt
  2. +17 −1 pyramid/renderers.py
  3. +22 −1 pyramid/tests/test_renderers.py
  4. +9 −4 pyramid/tests/test_view.py
  5. +1 −2 pyramid/view.py
View
@@ -7,6 +7,12 @@ Internals
- Remove ``compat`` code that served only the purpose of providing backwards
compatibility with Python 2.4.
+- Add a deprecation warning for non-API function
+ ``pyramid.renderers.renderer_from_name`` which has seen use in the wild.
+
+- Add a ``clone`` method to ``pyramid.renderers.RendererHelper`` for use by
+ the ``pyramid.view.view_config`` decorator.
+
Documentation
-------------
View
@@ -3,6 +3,7 @@
import threading
from zope.interface import implements
+from zope.deprecation import deprecated
from pyramid.interfaces import IChameleonLookup
from pyramid.interfaces import IChameleonTranslate
@@ -335,10 +336,16 @@ def template_renderer_factory(info, impl, lock=registry_lock):
lock.release()
return lookup(info)
-# XXX deprecate
def renderer_from_name(path, package=None):
return RendererHelper(name=path, package=package).renderer
+deprecated(
+ 'renderer_from_name',
+ 'The "pyramid.renderers.renderer_from_name" function was never an API. '
+ 'However, its use has been observed "in the wild." It will disappear in '
+ 'the next major release. To replace it, use the '
+ '``pyramid.renderers.get_renderer`` API instead. ')
+
class RendererHelper(object):
implements(IRendererInfo)
def __init__(self, name=None, package=None, registry=None):
@@ -453,3 +460,12 @@ def _make_response(self, result, request):
response.cache_expires = cache_for
return response
+ def clone(self, name=None, package=None, registry=None):
+ if name is None:
+ name = self.name
+ if package is None:
+ package = self.package
+ if registry is None:
+ registry = self.registry
+ return self.__class__(name=name, package=package, registry=registry)
+
@@ -341,11 +341,15 @@ def test___call__reload_assets_false(self):
class TestRendererFromName(unittest.TestCase):
def setUp(self):
+ from zope.deprecation import __show__
+ __show__.off()
self.config = cleanUp()
def tearDown(self):
cleanUp()
-
+ from zope.deprecation import __show__
+ __show__.on()
+
def _callFUT(self, path, package=None):
from pyramid.renderers import renderer_from_name
return renderer_from_name(path, package)
@@ -687,6 +691,23 @@ def test__make_response_with_real_request(self):
self.assertEqual(response.status, '406 You Lose')
self.assertEqual(response.body, 'abc')
+ def test_clone_noargs(self):
+ helper = self._makeOne('name', 'package', 'registry')
+ cloned_helper = helper.clone()
+ self.assertEqual(cloned_helper.name, 'name')
+ self.assertEqual(cloned_helper.package, 'package')
+ self.assertEqual(cloned_helper.registry, 'registry')
+ self.assertFalse(helper is cloned_helper)
+
+ def test_clone_allargs(self):
+ helper = self._makeOne('name', 'package', 'registry')
+ cloned_helper = helper.clone(name='name2', package='package2',
+ registry='registry2')
+ self.assertEqual(cloned_helper.name, 'name2')
+ self.assertEqual(cloned_helper.package, 'package2')
+ self.assertEqual(cloned_helper.registry, 'registry2')
+ self.assertFalse(helper is cloned_helper)
+
class Test_render(unittest.TestCase):
def setUp(self):
self.config = testing.setUp()
@@ -399,10 +399,17 @@ def test_call_with_renderer_IRendererInfo(self):
# see https://github.com/Pylons/pyramid/pull/234
from pyramid.interfaces import IRendererInfo
import pyramid.tests
+ outerself = self
class DummyRendererHelper(object):
implements(IRendererInfo)
name = 'fixtures/minimal.pt'
package = pyramid.tests
+ def clone(self, name=None, package=None, registry=None):
+ outerself.assertEqual(name, self.name)
+ outerself.assertEqual(package, self.package)
+ outerself.assertEqual(registry, context.config.registry)
+ self.cloned = True
+ return self
renderer_helper = DummyRendererHelper()
decorator = self._makeOne(renderer=renderer_helper)
venusian = DummyVenusian()
@@ -414,10 +421,8 @@ def foo(): pass
settings = call_venusian(venusian, context)
self.assertEqual(len(settings), 1)
renderer = settings[0]['renderer']
- self.assertFalse(renderer is renderer_helper)
- self.assertEqual(renderer.name, 'fixtures/minimal.pt')
- self.assertEqual(renderer.package, pyramid.tests)
- self.assertEqual(renderer.registry, context.config.registry)
+ self.assertTrue(renderer is renderer_helper)
+ self.assertTrue(renderer.cloned)
class Test_append_slash_notfound_view(BaseTest, unittest.TestCase):
def _callFUT(self, context, request):
View
@@ -1,6 +1,5 @@
import mimetypes
import venusian
-import warnings
from zope.interface import providedBy
from zope.deprecation import deprecated
@@ -226,7 +225,7 @@ def callback(context, name, ob):
elif IRendererInfo.providedBy(renderer):
# create a new rendererinfo to clear out old registry on a
# rescan, see https://github.com/Pylons/pyramid/pull/234
- renderer = RendererHelper(name=renderer.name,
+ renderer = renderer.clone(name=renderer.name,
package=info.module,
registry=context.config.registry)
settings['renderer'] = renderer

0 comments on commit 73c0aee

Please sign in to comment.