Mercurial > hg > decoupage
changeset 63:9c570aed2246
move app_conf parsing logic to factory.py
author | Jeff Hammel <jhammel@mozilla.com> |
---|---|
date | Tue, 14 Dec 2010 22:03:50 -0800 |
parents | 0890ec7069f3 |
children | 613ffeec2be5 |
files | decoupage/factory.py decoupage/web.py |
diffstat | 2 files changed, 12 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- a/decoupage/factory.py Mon Nov 29 17:53:20 2010 -0800 +++ b/decoupage/factory.py Tue Dec 14 22:03:50 2010 -0800 @@ -1,8 +1,16 @@ from web import Decoupage from paste.httpexceptions import HTTPExceptionHandler +def namespace_conf(keystr, app_conf): + keystr += '.' + return dict([(key.split(keystr, 1)[-1], value) + for key, value in app_conf.items() + if key.startswith(keystr) ]) + + def factory(global_conf, **app_conf): """create a webob view and wrap it in middleware""" + app_conf = namespace_conf('decoupage', app_conf) app = Decoupage(**app_conf) return HTTPExceptionHandler(app)
--- a/decoupage/web.py Mon Nov 29 17:53:20 2010 -0800 +++ b/decoupage/web.py Tue Dec 14 22:03:50 2010 -0800 @@ -33,14 +33,14 @@ 'template_directories': '' # list of directories to look for templates } - def __init__(self, **app_conf): + def __init__(self, **kw): # set defaults from app configuration - kw = self.app_conf('decoupage', app_conf) for key in self.defaults: setattr(self, key, kw.get(key, self.defaults[key])) # configure defaults + assert self.directory, "Decoupage: directory not specified" self.auto_reload = self.auto_reload.lower() == 'true' self.cascade = self.cascade.lower() == 'true' self.directory = self.directory.rstrip(os.path.sep) @@ -54,8 +54,8 @@ self.fileserver = FileApp # pluggable formats - s = 'decoupage.format.' - _format_args = [ (i.split(s, 1)[-1], j) for i, j in app_conf.items() + s = 'format.' + _format_args = [ (i.split(s, 1)[-1], j) for i, j in kw.items() if i.startswith(s) ] format_args = {} for i, j in _format_args: @@ -309,9 +309,3 @@ if key in self.formatters: formatter = self.formatters[key](value) - - def app_conf(self, keystr, app_conf): - keystr += '.' - return dict([(key.split(keystr, 1)[-1], value) - for key, value in app_conf.items() - if key.startswith(keystr) ])