view captchamiddleware/example.py @ 8:59245309f054 default tip

conform to modern version of lxmlmiddleware
author k0s <k0scist@gmail.com>
date Fri, 26 Feb 2010 15:40:56 -0500
parents ce757057961c
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))