comparison bitsyblog/factory.py @ 70:f6a6a4b072e7

complete overhaul to allow event handlers
author Jeff Hammel <jhammel@mozilla.com>
date Wed, 07 Jul 2010 16:18:19 -0700
parents 0af1f4ae328d
children 0c98d1c2c6df
comparison
equal deleted inserted replaced
69:bcc3a59713c3 70:f6a6a4b072e7
9 'subject', 9 'subject',
10 'n_links', 10 'n_links',
11 'help_file', 11 'help_file',
12 'header', 12 'header',
13 'template_directories', 13 'template_directories',
14 'feed_items']) 14 'feed_items',
15 ])
16
17 def get_args(app_conf):
18 """return arguments for bitsyblog and its handlers"""
19 key_str = 'bitsyblog.'
20 bitsyblog_args = {}
21 handler_args = {}
22 for key, value in app_conf.items():
23 if key.startswith(key_str):
24 key = key.split(key_str, 1)[-1]
25 if key in config:
26 bitysblog_args[key] = value
27 else:
28 if '.' in key:
29 section, key = key.split('.', 1)
30 handler_args.setdefault(section, {})[key] = value
31 return bitsyblog_args, handler_args
15 32
16 def factory(global_conf, **app_conf): 33 def factory(global_conf, **app_conf):
17 """make bitsyauth app and wrap it in middleware""" 34 """make bitsyauth app and wrap it in middleware"""
18 key_str = 'bitsyblog.%s' 35 bitsyblog_args, handler_args = get_args(app_conf)
19 args = dict([ (key, app_conf[ key_str % key]) for key in config
20 if app_conf.has_key(key_str % key) ])
21 app = BitsyBlog(**args) 36 app = BitsyBlog(**args)
22 secret = app_conf.get('secret', 'secret') 37 secret = app_conf.get('secret', 'secret')
23 return BitsyAuth(HTTPExceptionHandler(app), 38 return BitsyAuth(HTTPExceptionHandler(app),
24 global_conf, 39 global_conf,
25 app.passwords, 40 app.passwords,
28 secret) 43 secret)
29 44
30 45
31 def bitsierfactory(global_conf, **app_conf): 46 def bitsierfactory(global_conf, **app_conf):
32 """make single-user bitsyblog""" 47 """make single-user bitsyblog"""
33 key_str = 'bitsyblog.%s' 48 bitsyblog_args, handler_args = get_args(app_conf)
34 args = dict([ (key, app_conf[ key_str % key]) for key in config 49 user = app_conf['bitsyblog.user'] # ensure this exist
35 if app_conf.has_key(key_str % key) ])
36 user = app_conf['bitsyblog.user']
37 app = BitsierBlog(**args) 50 app = BitsierBlog(**args)
38 app.user = user 51 app.user = user
39 secret = app_conf.get('secret', 'secret') 52 secret = app_conf.get('secret', 'secret')
40 auth = BitsyAuth(HTTPExceptionHandler(app), 53 auth = BitsyAuth(HTTPExceptionHandler(app),
41 global_conf, 54 global_conf,