config.add_wsgi_app?

32 views
Skip to first unread message

Michael Kerrin

unread,
Dec 5, 2011, 7:57:53 AM12/5/11
to pylons-...@googlegroups.com
Hi,

I am starting to use Pyramid for a project and I want to integrate some third party code of mine that has already been developed and provides a WSGI application already.

Ideally I want some code in my entry point to my Pyramid app that does the following::

def main(global_config, **settings):
    config = Configurator(...)
    ...
    mywsgiapp = WSGIApp(app_config_settings)
    config.add_wsgi_app(mywsgiapp, name = "application_namespace")
    ...

My rational for this is that my application shares a lot of configuration that is already defined for Pyramid that I can reuse. But I also want to support other web frameworks, but with an minimal amount of dependencies and options on my third party code.

Pyramid views and WSGI applications implement two different apis, which is fine but I would like to think (or explore the idea) that the WSGI interface can be used as a gateway between frameworks as well as from framework <-> server.

So my question is has anyone looked into doing this?

Thanks,
Michael

--
Blog: http://mkerrin.wordpress.com/
Twitter: http://twitter.com/michael_kerrin

Michael Merickel

unread,
Dec 5, 2011, 11:30:08 AM12/5/11
to pylons-...@googlegroups.com
Does this help? Basically you can add a view that is actually a wsgi application.

http://docs.pylonsproject.org/projects/pyramid/en/1.2-branch/api/wsgi.html 

--
You received this message because you are subscribed to the Google Groups "pylons-discuss" group.
To post to this group, send email to pylons-...@googlegroups.com.
To unsubscribe from this group, send email to pylons-discus...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/pylons-discuss?hl=en.

Michael Kerrin

unread,
Dec 5, 2011, 12:06:45 PM12/5/11
to pylons-...@googlegroups.com
Yipe, thanks for that. pyramid.wsgi.wsgiapp2 works with a small tweak as it doesn't support handling an object instance.

I know that it is meant to be a decorator on a method but I don't want my third party WSGI code to depend on pyramid so I am now trying to do the following:

wsgiapp =  WSGIApp(app_config_settings)
config.add_view(pyramid.wsgi.wsgiapp2(wsgiapp), name = 'jinja2js')

I get an attribute error, when the decorate tries to wrap the __name__ attribute from my app. Which doesn't have a __name__ as it is an instance of a class. I will add an issue for this.

Thanks for the hint,
Michael

Michael Merickel

unread,
Dec 5, 2011, 1:36:15 PM12/5/11
to pylons-...@googlegroups.com
As a quick fix you can just wrap your object in a function.

def my_wsgi_app(environ, start_response):
    return MyWsgiObj(environ, start_response)

config.add_view(wsgiapp2(my_wsgi_app), name='jinja2js')
Reply all
Reply to author
Forward
0 new messages