summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Kerrin <michael.kerrin@gmail.com>2011-12-06 13:25:56 +0000
committerMichael Kerrin <michael.kerrin@gmail.com>2011-12-06 13:38:12 +0000
commitdc474ec5ddf5915959d7ebe5493dd8e222485ce0 (patch)
tree86b48e4ed8e2d7fd4607d87b989bd2d85789d27a
parent8d1bd72b0d0c1227991a7c05e3a916020dd3fad9 (diff)
downloadpyramid-dc474ec5ddf5915959d7ebe5493dd8e222485ce0.tar.gz
pyramid-dc474ec5ddf5915959d7ebe5493dd8e222485ce0.tar.bz2
pyramid-dc474ec5ddf5915959d7ebe5493dd8e222485ce0.zip
Support passing callable object instances WSGI applications to the
`pyramid.wsgi.wsgiapp' and `pyramid.wsgi.wsgiapp2' decorators. This allows us to configure pyramid like so: config.add_view(pyramid.wsgi.wsgiapp2(MyWSGIApp(settings)))
-rw-r--r--pyramid/tests/test_wsgi.py24
-rw-r--r--pyramid/wsgi.py12
2 files changed, 34 insertions, 2 deletions
diff --git a/pyramid/tests/test_wsgi.py b/pyramid/tests/test_wsgi.py
index 06bcf1cb2..63499b43b 100644
--- a/pyramid/tests/test_wsgi.py
+++ b/pyramid/tests/test_wsgi.py
@@ -12,6 +12,14 @@ class WSGIAppTests(unittest.TestCase):
response = decorator(context, request)
self.assertEqual(response, dummyapp)
+ def test_decorator_object_instance(self):
+ context = DummyContext()
+ request = DummyRequest()
+ app = DummyApp()
+ decorator = self._callFUT(app)
+ response = decorator(context, request)
+ self.assertEqual(response, app)
+
class WSGIApp2Tests(unittest.TestCase):
def _callFUT(self, app):
from pyramid.wsgi import wsgiapp2
@@ -84,9 +92,25 @@ class WSGIApp2Tests(unittest.TestCase):
self.assertEqual(request.environ['PATH_INFO'], '/')
self.assertEqual(request.environ['SCRIPT_NAME'], '')
+ def test_decorator_on_callable_object_instance(self):
+ context = DummyContext()
+ request = DummyRequest()
+ request.subpath = ()
+ request.environ = {'SCRIPT_NAME':'/foo', 'PATH_INFO':'/'}
+ app = DummyApp()
+ decorator = self._callFUT(app)
+ response = decorator(context, request)
+ self.assertEqual(response, app)
+ self.assertEqual(request.environ['PATH_INFO'], '/')
+ self.assertEqual(request.environ['SCRIPT_NAME'], '/foo')
+
def dummyapp(environ, start_response):
""" """
+class DummyApp(object):
+ def __call__(self, environ, start_response):
+ """ """
+
class DummyContext:
pass
diff --git a/pyramid/wsgi.py b/pyramid/wsgi.py
index 3bbe31790..5fa23d554 100644
--- a/pyramid/wsgi.py
+++ b/pyramid/wsgi.py
@@ -31,7 +31,11 @@ def wsgiapp(wrapped):
"""
def decorator(context, request):
return request.get_response(wrapped)
- return wraps(wrapped)(decorator)
+
+ # Support case where wrapped is a callable object instance
+ if getattr(wrapped, '__name__', None):
+ return wraps(wrapped)(decorator)
+ return wraps(wrapped, ('__module__', '__doc__'))(decorator)
def wsgiapp2(wrapped):
""" Decorator to turn a WSGI application into a :app:`Pyramid`
@@ -67,4 +71,8 @@ def wsgiapp2(wrapped):
def decorator(context, request):
return call_app_with_subpath_as_path_info(request, wrapped)
- return wraps(wrapped)(decorator)
+
+ # Support case where wrapped is a callable object instance
+ if getattr(wrapped, '__name__', None):
+ return wraps(wrapped)(decorator)
+ return wraps(wrapped, ('__module__', '__doc__'))(decorator)