Mercurial > hg > commentator
annotate commentator/example.py @ 6:c95f1dfed329
some work to get commenting + captchas working together
author | k0s <k0scist@gmail.com> |
---|---|
date | Tue, 02 Mar 2010 11:44:10 -0500 |
parents | 1c95a3fa76c1 |
children |
rev | line source |
---|---|
0 | 1 import os |
2 | |
3 from middleware import Commentator | |
4 from paste.httpexceptions import HTTPExceptionHandler | |
5 from paste.urlparser import StaticURLParser | |
6 from pkg_resources import resource_filename | |
7 | |
8 | |
9 def factory(global_conf, **app_conf): | |
10 """create a webob view and wrap it in middleware""" | |
11 | |
12 keystr = 'commentator.' | |
13 args = dict([(key.split(keystr, 1)[-1], value) | |
14 for key, value in app_conf.items() | |
15 if key.startswith(keystr) ]) | |
16 app = StaticURLParser(app_conf['directory']) | |
17 commentator = Commentator(app, **args) | |
18 return HTTPExceptionHandler(commentator) | |
6
c95f1dfed329
some work to get commenting + captchas working together
k0s <k0scist@gmail.com>
parents:
0
diff
changeset
|
19 |
c95f1dfed329
some work to get commenting + captchas working together
k0s <k0scist@gmail.com>
parents:
0
diff
changeset
|
20 try: |
c95f1dfed329
some work to get commenting + captchas working together
k0s <k0scist@gmail.com>
parents:
0
diff
changeset
|
21 from captchamiddleware import CAPTCHAmiddleware |
0 | 22 |
6
c95f1dfed329
some work to get commenting + captchas working together
k0s <k0scist@gmail.com>
parents:
0
diff
changeset
|
23 def captcha_factory(global_conf, **app_conf): |
c95f1dfed329
some work to get commenting + captchas working together
k0s <k0scist@gmail.com>
parents:
0
diff
changeset
|
24 """create a webob view and wrap it in middleware""" |
c95f1dfed329
some work to get commenting + captchas working together
k0s <k0scist@gmail.com>
parents:
0
diff
changeset
|
25 |
c95f1dfed329
some work to get commenting + captchas working together
k0s <k0scist@gmail.com>
parents:
0
diff
changeset
|
26 # set up commenting on static files |
c95f1dfed329
some work to get commenting + captchas working together
k0s <k0scist@gmail.com>
parents:
0
diff
changeset
|
27 keystr = 'commentator.' |
c95f1dfed329
some work to get commenting + captchas working together
k0s <k0scist@gmail.com>
parents:
0
diff
changeset
|
28 args = dict([(key.split(keystr, 1)[-1], value) |
c95f1dfed329
some work to get commenting + captchas working together
k0s <k0scist@gmail.com>
parents:
0
diff
changeset
|
29 for key, value in app_conf.items() |
c95f1dfed329
some work to get commenting + captchas working together
k0s <k0scist@gmail.com>
parents:
0
diff
changeset
|
30 if key.startswith(keystr) ]) |
c95f1dfed329
some work to get commenting + captchas working together
k0s <k0scist@gmail.com>
parents:
0
diff
changeset
|
31 app = StaticURLParser(app_conf['directory']) |
c95f1dfed329
some work to get commenting + captchas working together
k0s <k0scist@gmail.com>
parents:
0
diff
changeset
|
32 commentator = Commentator(app, **args) |
c95f1dfed329
some work to get commenting + captchas working together
k0s <k0scist@gmail.com>
parents:
0
diff
changeset
|
33 |
c95f1dfed329
some work to get commenting + captchas working together
k0s <k0scist@gmail.com>
parents:
0
diff
changeset
|
34 # install the CAPTCHAmiddleware |
c95f1dfed329
some work to get commenting + captchas working together
k0s <k0scist@gmail.com>
parents:
0
diff
changeset
|
35 keystring = 'captcha.' |
c95f1dfed329
some work to get commenting + captchas working together
k0s <k0scist@gmail.com>
parents:
0
diff
changeset
|
36 args = dict([(key.split(keystr, 1)[-1], value) |
c95f1dfed329
some work to get commenting + captchas working together
k0s <k0scist@gmail.com>
parents:
0
diff
changeset
|
37 for key, value in app_conf.items() |
c95f1dfed329
some work to get commenting + captchas working together
k0s <k0scist@gmail.com>
parents:
0
diff
changeset
|
38 if key.startswith(keystr) ]) |
c95f1dfed329
some work to get commenting + captchas working together
k0s <k0scist@gmail.com>
parents:
0
diff
changeset
|
39 captcha = CAPTCHAmiddleware(commentator, **args) |
c95f1dfed329
some work to get commenting + captchas working together
k0s <k0scist@gmail.com>
parents:
0
diff
changeset
|
40 |
c95f1dfed329
some work to get commenting + captchas working together
k0s <k0scist@gmail.com>
parents:
0
diff
changeset
|
41 return HTTPExceptionHandler(captcha) |
c95f1dfed329
some work to get commenting + captchas working together
k0s <k0scist@gmail.com>
parents:
0
diff
changeset
|
42 |
c95f1dfed329
some work to get commenting + captchas working together
k0s <k0scist@gmail.com>
parents:
0
diff
changeset
|
43 except ImportError: |
c95f1dfed329
some work to get commenting + captchas working together
k0s <k0scist@gmail.com>
parents:
0
diff
changeset
|
44 pass |