repoze.bfg.wsgi

wsgiapp(wrapped)

Decorator to turn a WSGI application into a repoze.bfg view callable. This decorator differs from the repoze.bfg.wsgi.wsgiapp2() decorator inasmuch as fixups of PATH_INFO and SCRIPT_NAME within the WSGI environment are not performed before the application is invoked.

E.g., the following in a views.py module:

@wsgiapp
def hello_world(environ, start_response):
    body = 'Hello world'
    start_response('200 OK', [ ('Content-Type', 'text/plain'),
                               ('Content-Length', len(body)) ] )
    return [body]

Allows the following ZCML view declaration to be made:

<view
   view=".views.hello_world"
   name="hello_world.txt"
 />

Or the following call to repoze.bfg.configuration.Configurator.add_view():

from views import hello_world
config.add_view(hello_world, name='hello_world.txt')

The wsgiapp decorator will convert the result of the WSGI application to a Response and return it to repoze.bfg as if the WSGI app were a repoze.bfg view.

wsgiapp2(wrapped)

Decorator to turn a WSGI application into a repoze.bfg view callable. This decorator differs from the repoze.bfg.wsgi.wsgiapp() decorator inasmuch as fixups of PATH_INFO and SCRIPT_NAME within the WSGI environment are performed before the application is invoked.

E.g. the following in a views.py module:

@wsgiapp2
def hello_world(environ, start_response):
    body = 'Hello world'
    start_response('200 OK', [ ('Content-Type', 'text/plain'),
                               ('Content-Length', len(body)) ] )
    return [body]

Allows the following ZCML view declaration to be made:

<view
   view=".views.hello_world"
   name="hello_world.txt"
 />

Or the following call to repoze.bfg.configuration.Configurator.add_view():

from views import hello_world
config.add_view(hello_world, name='hello_world.txt')

The wsgiapp2 decorator will convert the result of the WSGI application to a Response and return it to repoze.bfg as if the WSGI app were a repoze.bfg view. The SCRIPT_NAME and PATH_INFO values present in the WSGI environment are fixed up before the application is invoked.

Previous topic

repoze.bfg.view

Next topic

ZCML Directives

This Page