view captchamiddleware/example.py @ 2:c861518b2a44

fix bug whereby forbidden characters cause issues
author k0s <k0scist@gmail.com>
date Tue, 23 Feb 2010 19:50:23 -0500
parents 21ec6325ae0e
children ce757057961c
line wrap: on
line source

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

def example_app(environ, start_response):
    return Response('<html><body><p>method=%s</p><form method="post">Hello, world!<input type="submit"/></form></body></html>' % environ['REQUEST_METHOD'])(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))