summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Anderson <sontek@gmail.com>2015-01-01 20:15:12 -0800
committerJohn Anderson <sontek@gmail.com>2015-01-01 20:15:12 -0800
commit303abc8b585d97c75773b3cfa48b6e748c96fd64 (patch)
treeb00acc8b5d0d28a7fbfdef7d88c5c343488070c8
parenta62462606704081b37ae0cb4c9f07a4690480609 (diff)
downloadpyramid-303abc8b585d97c75773b3cfa48b6e748c96fd64.tar.gz
pyramid-303abc8b585d97c75773b3cfa48b6e748c96fd64.tar.bz2
pyramid-303abc8b585d97c75773b3cfa48b6e748c96fd64.zip
Move _get_response_factory to pyramid.response
-rw-r--r--pyramid/renderers.py4
-rw-r--r--pyramid/request.py7
-rw-r--r--pyramid/response.py17
-rw-r--r--pyramid/testing.py8
-rw-r--r--pyramid/tests/test_response.py17
-rw-r--r--pyramid/tests/test_util.py11
-rw-r--r--pyramid/util.py12
7 files changed, 34 insertions, 42 deletions
diff --git a/pyramid/renderers.py b/pyramid/renderers.py
index 51dbd318b..d57671865 100644
--- a/pyramid/renderers.py
+++ b/pyramid/renderers.py
@@ -18,15 +18,13 @@ from pyramid.compat import (
text_type,
)
-from pyramid.util import _get_response_factory
-
from pyramid.decorator import reify
from pyramid.events import BeforeRender
from pyramid.path import caller_package
-from pyramid.response import Response
+from pyramid.response import Response, _get_response_factory
from pyramid.threadlocal import get_current_registry
# API
diff --git a/pyramid/request.py b/pyramid/request.py
index fc957fae2..b2e2efe05 100644
--- a/pyramid/request.py
+++ b/pyramid/request.py
@@ -20,16 +20,13 @@ from pyramid.compat import (
from pyramid.decorator import reify
from pyramid.i18n import LocalizerRequestMixin
-from pyramid.response import Response
+from pyramid.response import Response, _get_response_factory
from pyramid.security import (
AuthenticationAPIMixin,
AuthorizationAPIMixin,
)
from pyramid.url import URLMethodsMixin
-from pyramid.util import (
- InstancePropertyMixin,
- _get_response_factory,
-)
+from pyramid.util import InstancePropertyMixin
class TemplateContext(object):
pass
diff --git a/pyramid/response.py b/pyramid/response.py
index d11fd0123..892e5dfff 100644
--- a/pyramid/response.py
+++ b/pyramid/response.py
@@ -8,7 +8,8 @@ import venusian
from webob import Response as _Response
from zope.interface import implementer
-from pyramid.interfaces import IResponse
+from pyramid.interfaces import IResponse, IResponseFactory
+
def init_mimetypes(mimetypes):
# this is a function so it can be unittested
@@ -143,7 +144,7 @@ class response_adapter(object):
@response_adapter(dict, list)
def myadapter(ob):
return Response(json.dumps(ob))
-
+
This method will have no effect until a :term:`scan` is performed
agains the package or module which contains it, ala:
@@ -167,3 +168,15 @@ class response_adapter(object):
def __call__(self, wrapped):
self.venusian.attach(wrapped, self.register, category='pyramid')
return wrapped
+
+
+def _get_response_factory(registry):
+ """ Obtain a :class: `pyramid.response.Response` using the
+ `pyramid.interfaces.IResponseFactory`.
+ """
+ response_factory = registry.queryUtility(
+ IResponseFactory,
+ default=lambda r: Response()
+ )
+
+ return response_factory
diff --git a/pyramid/testing.py b/pyramid/testing.py
index 66c694b31..667e6af4e 100644
--- a/pyramid/testing.py
+++ b/pyramid/testing.py
@@ -21,7 +21,7 @@ from pyramid.compat import (
from pyramid.config import Configurator
from pyramid.decorator import reify
from pyramid.path import caller_package
-from pyramid.response import Response
+from pyramid.response import Response, _get_response_factory
from pyramid.registry import Registry
from pyramid.security import (
@@ -39,10 +39,8 @@ from pyramid.threadlocal import (
from pyramid.i18n import LocalizerRequestMixin
from pyramid.request import CallbackMethodsMixin
from pyramid.url import URLMethodsMixin
-from pyramid.util import (
- InstancePropertyMixin,
- _get_response_factory
- )
+from pyramid.util import InstancePropertyMixin
+
_marker = object()
diff --git a/pyramid/tests/test_response.py b/pyramid/tests/test_response.py
index 84ec57757..ad55882c9 100644
--- a/pyramid/tests/test_response.py
+++ b/pyramid/tests/test_response.py
@@ -8,7 +8,7 @@ class TestResponse(unittest.TestCase):
def _getTargetClass(self):
from pyramid.response import Response
return Response
-
+
def test_implements_IResponse(self):
from pyramid.interfaces import IResponse
cls = self._getTargetClass()
@@ -119,7 +119,7 @@ class Test_patch_mimetypes(unittest.TestCase):
result = self._callFUT(module)
self.assertEqual(result, True)
self.assertEqual(module.initted, True)
-
+
def test_missing_init(self):
class DummyMimetypes(object):
pass
@@ -174,6 +174,17 @@ class TestResponseAdapter(unittest.TestCase):
self.assertEqual(dummy_venusian.attached,
[(foo, dec.register, 'pyramid')])
+
+class TestGetResponseFactory(unittest.TestCase):
+ def test_get_factory(self):
+ from pyramid.registry import Registry
+ from pyramid.response import Response, _get_response_factory
+
+ registry = Registry()
+ response = _get_response_factory(registry)(None)
+ self.assertTrue(isinstance(response, Response))
+
+
class Dummy(object):
pass
@@ -190,5 +201,3 @@ class DummyVenusian(object):
def attach(self, wrapped, fn, category=None):
self.attached.append((wrapped, fn, category))
-
-
diff --git a/pyramid/tests/test_util.py b/pyramid/tests/test_util.py
index ba128eede..ac5ea0683 100644
--- a/pyramid/tests/test_util.py
+++ b/pyramid/tests/test_util.py
@@ -619,17 +619,6 @@ class TestActionInfo(unittest.TestCase):
"Line 0 of file filename:\n linerepr ")
-class TestGetResponseFactory(unittest.TestCase):
- def test_get_factory(self):
- from pyramid.util import _get_response_factory
- from pyramid.registry import Registry
- from pyramid.response import Response
-
- registry = Registry()
- response = _get_response_factory(registry)(None)
- self.assertTrue(isinstance(response, Response))
-
-
def dummyfunc(): pass
class Dummy(object):
diff --git a/pyramid/util.py b/pyramid/util.py
index 7aecca19c..4ca2937a1 100644
--- a/pyramid/util.py
+++ b/pyramid/util.py
@@ -555,15 +555,3 @@ def action_method(wrapped):
functools.update_wrapper(wrapper, wrapped)
wrapper.__docobj__ = wrapped
return wrapper
-
-
-def _get_response_factory(registry):
- """ Obtain a :class: `pyramid.response.Response` using the
- `pyramid.interfaces.IResponseFactory`.
- """
- response_factory = registry.queryUtility(
- IResponseFactory,
- default=lambda r: Response()
- )
-
- return response_factory