annotate 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
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):
4
ce757057961c flow contol now works; bumping version
k0s <k0scist@gmail.com>
parents: 2
diff changeset
6 method = environ['REQUEST_METHOD']
ce757057961c flow contol now works; bumping version
k0s <k0scist@gmail.com>
parents: 2
diff changeset
7 form = ''
ce757057961c flow contol now works; bumping version
k0s <k0scist@gmail.com>
parents: 2
diff changeset
8 if method != 'POST':
ce757057961c flow contol now works; bumping version
k0s <k0scist@gmail.com>
parents: 2
diff changeset
9 form = '<form method="post">Hello, world!<input type="submit"/></form>'
ce757057961c flow contol now works; bumping version
k0s <k0scist@gmail.com>
parents: 2
diff changeset
10
ce757057961c flow contol now works; bumping version
k0s <k0scist@gmail.com>
parents: 2
diff changeset
11 return Response('<html><body><p>method=%s</p>%s</body></html>' % (method, form))(environ, start_response)
0
21ec6325ae0e initial import of CAPTCHA middleware; unfinished
k0s <k0scist@gmail.com>
parents:
diff changeset
12
21ec6325ae0e initial import of CAPTCHA middleware; unfinished
k0s <k0scist@gmail.com>
parents:
diff changeset
13
21ec6325ae0e initial import of CAPTCHA middleware; unfinished
k0s <k0scist@gmail.com>
parents:
diff changeset
14 def factory(global_conf, **app_conf):
21ec6325ae0e initial import of CAPTCHA middleware; unfinished
k0s <k0scist@gmail.com>
parents:
diff changeset
15 """create a webob view and wrap it in middleware"""
21ec6325ae0e initial import of CAPTCHA middleware; unfinished
k0s <k0scist@gmail.com>
parents:
diff changeset
16 keystring = 'captcha.'
21ec6325ae0e initial import of CAPTCHA middleware; unfinished
k0s <k0scist@gmail.com>
parents:
diff changeset
17 args = dict([(key.split(keystr, 1)[-1], value)
21ec6325ae0e initial import of CAPTCHA middleware; unfinished
k0s <k0scist@gmail.com>
parents:
diff changeset
18 for key, value in app_conf.items()
21ec6325ae0e initial import of CAPTCHA middleware; unfinished
k0s <k0scist@gmail.com>
parents:
diff changeset
19 if key.startswith(keystr) ])
21ec6325ae0e initial import of CAPTCHA middleware; unfinished
k0s <k0scist@gmail.com>
parents:
diff changeset
20 return HTTPExceptionHandler(CAPTCHAmiddleware(example_app, **args))
21ec6325ae0e initial import of CAPTCHA middleware; unfinished
k0s <k0scist@gmail.com>
parents:
diff changeset
21