view captchamiddleware/example.py @ 5:6c6766109dac

adding README.txt and use it in setup.py long_description
author k0s <k0scist@gmail.com>
date Wed, 24 Feb 2010 20:21:47 -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))