Mercurial > hg > decoupage
comparison decoupage/web.py @ 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 | f5ca54558292 |
children | 613ffeec2be5 |
comparison
equal
deleted
inserted
replaced
62:0890ec7069f3 | 63:9c570aed2246 |
---|---|
31 'cascade': 'True', # whether to cascade configuration | 31 'cascade': 'True', # whether to cascade configuration |
32 'template': 'index.html', # XXX see below | 32 'template': 'index.html', # XXX see below |
33 'template_directories': '' # list of directories to look for templates | 33 'template_directories': '' # list of directories to look for templates |
34 } | 34 } |
35 | 35 |
36 def __init__(self, **app_conf): | 36 def __init__(self, **kw): |
37 | 37 |
38 # set defaults from app configuration | 38 # set defaults from app configuration |
39 kw = self.app_conf('decoupage', app_conf) | |
40 for key in self.defaults: | 39 for key in self.defaults: |
41 setattr(self, key, kw.get(key, self.defaults[key])) | 40 setattr(self, key, kw.get(key, self.defaults[key])) |
42 | 41 |
43 # configure defaults | 42 # configure defaults |
43 assert self.directory, "Decoupage: directory not specified" | |
44 self.auto_reload = self.auto_reload.lower() == 'true' | 44 self.auto_reload = self.auto_reload.lower() == 'true' |
45 self.cascade = self.cascade.lower() == 'true' | 45 self.cascade = self.cascade.lower() == 'true' |
46 self.directory = self.directory.rstrip(os.path.sep) | 46 self.directory = self.directory.rstrip(os.path.sep) |
47 assert os.path.isdir(self.directory) | 47 assert os.path.isdir(self.directory) |
48 self.template_directories = self.template_directories.split() # no spaces in directory names, for now | 48 self.template_directories = self.template_directories.split() # no spaces in directory names, for now |
52 | 52 |
53 # static file server | 53 # static file server |
54 self.fileserver = FileApp | 54 self.fileserver = FileApp |
55 | 55 |
56 # pluggable formats | 56 # pluggable formats |
57 s = 'decoupage.format.' | 57 s = 'format.' |
58 _format_args = [ (i.split(s, 1)[-1], j) for i, j in app_conf.items() | 58 _format_args = [ (i.split(s, 1)[-1], j) for i, j in kw.items() |
59 if i.startswith(s) ] | 59 if i.startswith(s) ] |
60 format_args = {} | 60 format_args = {} |
61 for i, j in _format_args: | 61 for i, j in _format_args: |
62 assert i.count('.') == 1, 'Illegal string or something' | 62 assert i.count('.') == 1, 'Illegal string or something' |
63 format_name, var_name = i.split('.') | 63 format_name, var_name = i.split('.') |
307 if key.startswith('/'): | 307 if key.startswith('/'): |
308 key = key[1:] | 308 key = key[1:] |
309 if key in self.formatters: | 309 if key in self.formatters: |
310 formatter = self.formatters[key](value) | 310 formatter = self.formatters[key](value) |
311 | 311 |
312 | |
313 def app_conf(self, keystr, app_conf): | |
314 keystr += '.' | |
315 return dict([(key.split(keystr, 1)[-1], value) | |
316 for key, value in app_conf.items() | |
317 if key.startswith(keystr) ]) |