Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Support adding WSGI applications as views during configuration #370

Merged
merged 1 commit into from

2 participants

@mkerrin

Support passing callable object instances as 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)))
@mkerrin mkerrin 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)))
dc474ec
@mcdonc mcdonc merged commit dc474ec into Pylons:master
@mcdonc
Owner

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Dec 6, 2011
  1. @mkerrin

    Support passing callable object instances WSGI applications to the

    mkerrin authored
    `pyramid.wsgi.wsgiapp' and `pyramid.wsgi.wsgiapp2' decorators.
    
    This allows us to configure pyramid like so:
    
        config.add_view(pyramid.wsgi.wsgiapp2(MyWSGIApp(settings)))
This page is out of date. Refresh to see the latest.
Showing with 34 additions and 2 deletions.
  1. +24 −0 pyramid/tests/test_wsgi.py
  2. +10 −2 pyramid/wsgi.py
View
24 pyramid/tests/test_wsgi.py
@@ -12,6 +12,14 @@ def test_decorator(self):
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 @@ def test_decorator_traversed_empty_no_view_name_no_script_name(self):
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
View
12 pyramid/wsgi.py
@@ -31,7 +31,11 @@ def hello_world(environ, start_response):
"""
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 hello_world(environ, start_response):
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)
Something went wrong with that request. Please try again.