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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
1c95a3fa76c1 initial commit of commentator
k0s <k0scist@gmail.com>
parents:
diff changeset
1 import os
1c95a3fa76c1 initial commit of commentator
k0s <k0scist@gmail.com>
parents:
diff changeset
2
1c95a3fa76c1 initial commit of commentator
k0s <k0scist@gmail.com>
parents:
diff changeset
3 from middleware import Commentator
1c95a3fa76c1 initial commit of commentator
k0s <k0scist@gmail.com>
parents:
diff changeset
4 from paste.httpexceptions import HTTPExceptionHandler
1c95a3fa76c1 initial commit of commentator
k0s <k0scist@gmail.com>
parents:
diff changeset
5 from paste.urlparser import StaticURLParser
1c95a3fa76c1 initial commit of commentator
k0s <k0scist@gmail.com>
parents:
diff changeset
6 from pkg_resources import resource_filename
1c95a3fa76c1 initial commit of commentator
k0s <k0scist@gmail.com>
parents:
diff changeset
7
1c95a3fa76c1 initial commit of commentator
k0s <k0scist@gmail.com>
parents:
diff changeset
8
1c95a3fa76c1 initial commit of commentator
k0s <k0scist@gmail.com>
parents:
diff changeset
9 def factory(global_conf, **app_conf):
1c95a3fa76c1 initial commit of commentator
k0s <k0scist@gmail.com>
parents:
diff changeset
10 """create a webob view and wrap it in middleware"""
1c95a3fa76c1 initial commit of commentator
k0s <k0scist@gmail.com>
parents:
diff changeset
11
1c95a3fa76c1 initial commit of commentator
k0s <k0scist@gmail.com>
parents:
diff changeset
12 keystr = 'commentator.'
1c95a3fa76c1 initial commit of commentator
k0s <k0scist@gmail.com>
parents:
diff changeset
13 args = dict([(key.split(keystr, 1)[-1], value)
1c95a3fa76c1 initial commit of commentator
k0s <k0scist@gmail.com>
parents:
diff changeset
14 for key, value in app_conf.items()
1c95a3fa76c1 initial commit of commentator
k0s <k0scist@gmail.com>
parents:
diff changeset
15 if key.startswith(keystr) ])
1c95a3fa76c1 initial commit of commentator
k0s <k0scist@gmail.com>
parents:
diff changeset
16 app = StaticURLParser(app_conf['directory'])
1c95a3fa76c1 initial commit of commentator
k0s <k0scist@gmail.com>
parents:
diff changeset
17 commentator = Commentator(app, **args)
1c95a3fa76c1 initial commit of commentator
k0s <k0scist@gmail.com>
parents:
diff changeset
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
1c95a3fa76c1 initial commit of commentator
k0s <k0scist@gmail.com>
parents:
diff changeset
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