annotate captchamiddleware/example.py @ 0:21ec6325ae0e

initial import of CAPTCHA middleware; unfinished
author k0s <k0scist@gmail.com>
date Sun, 24 Jan 2010 23:15:57 -0500
parents
children c861518b2a44
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
21ec6325ae0e initial import of CAPTCHA middleware; unfinished
k0s <k0scist@gmail.com>
parents:
diff changeset
1 from webob import Response
21ec6325ae0e initial import of CAPTCHA middleware; unfinished
k0s <k0scist@gmail.com>
parents:
diff changeset
2 from captchamiddleware import CAPTCHAmiddleware
21ec6325ae0e initial import of CAPTCHA middleware; unfinished
k0s <k0scist@gmail.com>
parents:
diff changeset
3 from paste.httpexceptions import HTTPExceptionHandler
21ec6325ae0e initial import of CAPTCHA middleware; unfinished
k0s <k0scist@gmail.com>
parents:
diff changeset
4
21ec6325ae0e initial import of CAPTCHA middleware; unfinished
k0s <k0scist@gmail.com>
parents:
diff changeset
5 def example_app(environ, start_response):
21ec6325ae0e initial import of CAPTCHA middleware; unfinished
k0s <k0scist@gmail.com>
parents:
diff changeset
6 return Response('<html><body><form method="post">Hello, world!<input type="submit"/></form></body></html>')(environ, start_response)
21ec6325ae0e initial import of CAPTCHA middleware; unfinished
k0s <k0scist@gmail.com>
parents:
diff changeset
7
21ec6325ae0e initial import of CAPTCHA middleware; unfinished
k0s <k0scist@gmail.com>
parents:
diff changeset
8
21ec6325ae0e initial import of CAPTCHA middleware; unfinished
k0s <k0scist@gmail.com>
parents:
diff changeset
9 def factory(global_conf, **app_conf):
21ec6325ae0e initial import of CAPTCHA middleware; unfinished
k0s <k0scist@gmail.com>
parents:
diff changeset
10 """create a webob view and wrap it in middleware"""
21ec6325ae0e initial import of CAPTCHA middleware; unfinished
k0s <k0scist@gmail.com>
parents:
diff changeset
11 keystring = 'captcha.'
21ec6325ae0e initial import of CAPTCHA middleware; unfinished
k0s <k0scist@gmail.com>
parents:
diff changeset
12 args = dict([(key.split(keystr, 1)[-1], value)
21ec6325ae0e initial import of CAPTCHA middleware; unfinished
k0s <k0scist@gmail.com>
parents:
diff changeset
13 for key, value in app_conf.items()
21ec6325ae0e initial import of CAPTCHA middleware; unfinished
k0s <k0scist@gmail.com>
parents:
diff changeset
14 if key.startswith(keystr) ])
21ec6325ae0e initial import of CAPTCHA middleware; unfinished
k0s <k0scist@gmail.com>
parents:
diff changeset
15 return HTTPExceptionHandler(CAPTCHAmiddleware(example_app, **args))
21ec6325ae0e initial import of CAPTCHA middleware; unfinished
k0s <k0scist@gmail.com>
parents:
diff changeset
16