summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGES.txt8
-rw-r--r--CONTRIBUTORS.txt2
-rw-r--r--docs/api/interfaces.rst3
-rw-r--r--docs/glossary.rst3
-rw-r--r--docs/narr/hooks.rst9
-rw-r--r--pyramid/config/factories.py5
-rw-r--r--pyramid/interfaces.py11
-rw-r--r--pyramid/path.py10
-rw-r--r--pyramid/renderers.py24
-rw-r--r--pyramid/tests/test_renderers.py6
-rw-r--r--pyramid/util.py5
11 files changed, 54 insertions, 32 deletions
diff --git a/CHANGES.txt b/CHANGES.txt
index 09a4bbf88..27052cf0f 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -125,6 +125,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/docs/api/interfaces.rst b/docs/api/interfaces.rst
index a62976d8a..de2a664a4 100644
--- a/docs/api/interfaces.rst
+++ b/docs/api/interfaces.rst
@@ -56,6 +56,9 @@ Other Interfaces
.. autointerface:: IRenderer
:members:
+ .. autointerface:: IResponseFactory
+ :members:
+
.. autointerface:: IViewMapperFactory
:members:
diff --git a/docs/glossary.rst b/docs/glossary.rst
index 911c22075..9c0ea8598 100644
--- a/docs/glossary.rst
+++ b/docs/glossary.rst
@@ -18,7 +18,8 @@ Glossary
response factory
An object which, provided a :term:`request` as a single positional
- argument, returns a Pyramid-compatible response.
+ argument, returns a Pyramid-compatible response. See
+ :class:`pyramid.interfaces.IResponseFactory`.
response
An object returned by a :term:`view callable` that represents response
diff --git a/docs/narr/hooks.rst b/docs/narr/hooks.rst
index 17cae2c67..4fd7670b9 100644
--- a/docs/narr/hooks.rst
+++ b/docs/narr/hooks.rst
@@ -364,9 +364,12 @@ Whenever :app:`Pyramid` returns a response from a view it creates a
object.
The factory that :app:`Pyramid` uses to create a response object instance can be
-changed by passing a ``response_factory`` argument to the constructor of the
-:term:`configurator`. This argument can be either a callable or a
-:term:`dotted Python name` representing a callable.
+changed by passing a :class:`pyramid.interfaces.IResponseFactory` argument to
+the constructor of the :term:`configurator`. This argument can be either a
+callable or a :term:`dotted Python name` representing a callable.
+
+The factory takes a single positional argument, which is a :term:`Request`
+object. The argument may be ``None``.
.. code-block:: python
:linenos:
diff --git a/pyramid/config/factories.py b/pyramid/config/factories.py
index d7a48ba93..15cfb796f 100644
--- a/pyramid/config/factories.py
+++ b/pyramid/config/factories.py
@@ -102,9 +102,8 @@ class FactoriesConfiguratorMixin(object):
""" The object passed as ``factory`` should be an object (or a
:term:`dotted Python name` which refers to an object) which
will be used by the :app:`Pyramid` as the default response
- objects. This factory object must have the same
- methods and attributes as the
- :class:`pyramid.request.Response` class.
+ objects. The factory should conform to the
+ :class:`pyramid.interfaces.IResponseFactory` interface.
.. note::
diff --git a/pyramid/interfaces.py b/pyramid/interfaces.py
index b21c6b9cc..0f1b4efc3 100644
--- a/pyramid/interfaces.py
+++ b/pyramid/interfaces.py
@@ -582,12 +582,11 @@ class IStaticURLInfo(Interface):
""" Generate a URL for the given path """
class IResponseFactory(Interface):
- """ A utility which generates a response factory """
- def __call__():
- """ Return a response factory (e.g. a callable that returns an object
- implementing IResponse, e.g. :class:`pyramid.response.Response`). It
- should accept all the arguments that the Pyramid Response class
- accepts."""
+ """ A utility which generates a response """
+ def __call__(request):
+ """ Return a response object implementing IResponse,
+ e.g. :class:`pyramid.response.Response`). It should handle the
+ case when ``request`` is ``None``."""
class IRequestFactory(Interface):
""" A utility which generates a request """
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
diff --git a/pyramid/util.py b/pyramid/util.py
index 4ca2937a1..18cef4602 100644
--- a/pyramid/util.py
+++ b/pyramid/util.py
@@ -15,10 +15,6 @@ from pyramid.exceptions import (
CyclicDependencyError,
)
-from pyramid.interfaces import (
- IResponseFactory,
- )
-
from pyramid.compat import (
iteritems_,
is_nonstr_iter,
@@ -29,7 +25,6 @@ from pyramid.compat import (
)
from pyramid.interfaces import IActionInfo
-from pyramid.response import Response
from pyramid.path import DottedNameResolver as _DottedNameResolver
class DottedNameResolver(_DottedNameResolver):