view captchamiddleware/example.py @ 4:ce757057961c

flow contol now works; bumping version
author k0s <k0scist@gmail.com>
date Wed, 24 Feb 2010 20:11:25 -0500
parents c861518b2a44
children
line wrap: on
line source

from webob import Response
from captchamiddleware import CAPTCHAmiddleware
from paste.httpexceptions import HTTPExceptionHandler

def example_app(environ, start_response):
    method = environ['REQUEST_METHOD']
    form = ''
    if method != 'POST':
        form = '<form method="post">Hello, world!<input type="submit"/></form>'

    return Response('<html><body><p>method=%s</p>%s</body></html>' % (method, form))(environ, start_response)


def factory(global_conf, **app_conf):
    """create a webob view and wrap it in middleware"""
    keystring = 'captcha.'
    args = dict([(key.split(keystr, 1)[-1], value)
                 for key, value in app_conf.items()
                 if key.startswith(keystr) ])
    return HTTPExceptionHandler(CAPTCHAmiddleware(example_app, **args))