Mercurial > hg > bitsyblog
annotate bitsyblog/factory.py @ 50:cf77bd13aad9
add support for headers
author | k0s <k0scist@gmail.com> |
---|---|
date | Sat, 26 Dec 2009 21:41:00 -0500 |
parents | c228832db770 |
children | 3ddb2ca12178 |
rev | line source |
---|---|
45 | 1 from bitsyauth import BitsyAuth |
0
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
2 from bitsyblog import BitsyBlog, BitsierBlog |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
3 from getpass import getpass |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
4 from paste.httpexceptions import HTTPExceptionHandler |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
5 |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
6 def factory(global_conf, **app_conf): |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
7 """make bitsyauth app and wrap it in middleware""" |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
8 |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
9 config = [ 'file_dir', 'date_format', 'subject', 'n_links', 'help_file' ] |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
10 key_str = 'bitsyblog.%s' |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
11 args = dict([ (key, app_conf[ key_str % key]) for key in config |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
12 if app_conf.has_key(key_str % key) ]) |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
13 app = BitsyBlog(**args) |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
14 secret = app_conf.get('secret', 'secret') |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
15 return BitsyAuth(HTTPExceptionHandler(app), global_conf, app.passwords, app.newuser, 'bitsyblog', secret) |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
16 |
40 | 17 |
0
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
18 def bitsierfactory(global_conf, **app_conf): |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
19 """make single-user bitsyblog""" |
50 | 20 config = [ 'file_dir', 'date_format', 'subject', 'n_links', 'help_file', 'header' ] |
0
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
21 key_str = 'bitsyblog.%s' |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
22 args = dict([ (key, app_conf[ key_str % key]) for key in config |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
23 if app_conf.has_key(key_str % key) ]) |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
24 user = app_conf['bitsyblog.user'] |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
25 app = BitsierBlog(**args) |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
26 app.user = user |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
27 secret = app_conf.get('secret', 'secret') |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
28 auth = BitsyAuth(HTTPExceptionHandler(app), global_conf, app.passwords, newuser=None, site='bitsyblog', secret=secret) |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
29 if not user in app.users: |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
30 pw = getpass('Enter password for %s: ' % user) |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
31 app.newuser(user, auth.hash(app.user, pw)) |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
32 return auth |