diff options
| -rw-r--r-- | CHANGES.txt | 8 | ||||
| -rw-r--r-- | CONTRIBUTORS.txt | 2 | ||||
| -rw-r--r-- | pyramid/path.py | 10 | ||||
| -rw-r--r-- | pyramid/renderers.py | 24 | ||||
| -rw-r--r-- | pyramid/tests/test_renderers.py | 6 |
5 files changed, 36 insertions, 14 deletions
diff --git a/CHANGES.txt b/CHANGES.txt index 832a2c216..2dee64a84 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -120,6 +120,14 @@ Bug Fixes - Fix route generation for static view asset specifications having no path. See https://github.com/Pylons/pyramid/pull/1377 +- Allow the ``pyramid.renderers.JSONP`` renderer to work even if there is no + valid request object. In this case it will not wrap the object in a + callback and thus behave just like the ``pyramid.renderers.JSON` renderer. + See https://github.com/Pylons/pyramid/pull/1561 + +- Prevent "parameters to load are deprecated" ``DeprecationWarning`` + from setuptools>=11.3. See https://github.com/Pylons/pyramid/pull/1541 + Deprecations ------------ diff --git a/CONTRIBUTORS.txt b/CONTRIBUTORS.txt index adf2224a5..319d41434 100644 --- a/CONTRIBUTORS.txt +++ b/CONTRIBUTORS.txt @@ -240,3 +240,5 @@ Contributors - Adrian Teng, 2014/12/17 - Ilja Everila, 2015/02/05 + +- Geoffrey T. Dairiki, 2015/02/06 diff --git a/pyramid/path.py b/pyramid/path.py index 470e766f8..f2d8fff55 100644 --- a/pyramid/path.py +++ b/pyramid/path.py @@ -337,8 +337,14 @@ class DottedNameResolver(Resolver): value = package.__name__ else: value = package.__name__ + value - return pkg_resources.EntryPoint.parse( - 'x=%s' % value).load(False) + # Calling EntryPoint.load with an argument is deprecated. + # See https://pythonhosted.org/setuptools/history.html#id8 + ep = pkg_resources.EntryPoint.parse('x=%s' % value) + if hasattr(ep, 'resolve'): + # setuptools>=10.2 + return ep.resolve() # pragma: NO COVER + else: + return ep.load(False) # pragma: NO COVER def _zope_dottedname_style(self, value, package): """ package.module.attr style """ diff --git a/pyramid/renderers.py b/pyramid/renderers.py index d840cc317..3c35551ea 100644 --- a/pyramid/renderers.py +++ b/pyramid/renderers.py @@ -24,7 +24,7 @@ from pyramid.events import BeforeRender from pyramid.path import caller_package -from pyramid.response import Response, _get_response_factory +from pyramid.response import _get_response_factory from pyramid.threadlocal import get_current_registry # API @@ -355,19 +355,19 @@ class JSONP(JSON): ``self.param_name`` is present in request.GET; otherwise returns plain-JSON encoded string with content-type ``application/json``""" def _render(value, system): - request = system['request'] + request = system.get('request') default = self._make_default(request) val = self.serializer(value, default=default, **self.kw) - callback = request.GET.get(self.param_name) - if callback is None: - ct = 'application/json' - body = val - else: - ct = 'application/javascript' - body = '%s(%s);' % (callback, val) - response = request.response - if response.content_type == response.default_content_type: - response.content_type = ct + ct = 'application/json' + body = val + if request is not None: + callback = request.GET.get(self.param_name) + if callback is not None: + ct = 'application/javascript' + body = '%s(%s);' % (callback, val) + response = request.response + if response.content_type == response.default_content_type: + response.content_type = ct return body return _render diff --git a/pyramid/tests/test_renderers.py b/pyramid/tests/test_renderers.py index 30fdef051..6d79cc291 100644 --- a/pyramid/tests/test_renderers.py +++ b/pyramid/tests/test_renderers.py @@ -602,6 +602,12 @@ class TestJSONP(unittest.TestCase): self.assertEqual(request.response.content_type, 'application/json') + def test_render_without_request(self): + renderer_factory = self._makeOne() + renderer = renderer_factory(None) + result = renderer({'a':'1'}, {}) + self.assertEqual(result, '{"a": "1"}') + class Dummy: pass |
