comparison makeitso/dispatcher.py @ 20:6d1c703c5ffc

use tempita instead of genshi since we have it already (and dont need a really complex templating system)
author Jeff Hammel <jhammel@mozilla.com>
date Wed, 17 Nov 2010 10:57:59 -0800
parents 02498337c747
children 1b9573832f33
comparison
equal deleted inserted replaced
19:c46ec69d6253 20:6d1c703c5ffc
1 """ 1 """
2 request dispatcher: 2 request dispatcher:
3 data persisting across requests should go here 3 data persisting across requests should go here
4 """ 4 """
5 5
6 import os
7
8 from handlers import Index 6 from handlers import Index
9
10 from genshi.template import TemplateLoader
11 from paste.fileapp import FileApp
12 from pkg_resources import resource_filename
13 from webob import Request, Response, exc 7 from webob import Request, Response, exc
14 8
15 class Dispatcher(object): 9 class Dispatcher(object):
16 10
17 ### class level variables 11 ### class level variables
18 defaults = { 'auto_reload': 'False', 12 defaults = { 'app': None, }
19 'template_dirs': '',
20 'app': None,
21 'name': 'anonymous' }
22 13
23 def __init__(self, **kw): 14 def __init__(self, **kw):
24 15
25 # set instance parameters from kw and defaults 16 # set instance parameters from kw and defaults
26 for key in self.defaults: 17 for key in self.defaults:
27 setattr(self, key, kw.get(key, self.defaults[key])) 18 setattr(self, key, kw.get(key, self.defaults[key]))
28 self.auto_reload = self.auto_reload.lower() == 'true'
29 19
30 # request handlers 20 # request handlers
31 self.handlers = [ Index ] 21 self.handlers = [ Index ]
32 22
33 # endpoint app if used as middleware 23 # endpoint app if used as middleware
34 if self.app: 24 if self.app:
35 assert hasattr(self.app, '__call__') 25 assert hasattr(self.app, '__call__')
36
37 # template loader
38 self.template_dirs = self.template_dirs.split()
39 self.template_dirs.append(resource_filename(__name__, 'templates'))
40 self.loader = TemplateLoader(self.template_dirs,
41 auto_reload=self.auto_reload)
42 26
43 def __call__(self, environ, start_response): 27 def __call__(self, environ, start_response):
44 28
45 # get a request object 29 # get a request object
46 request = Request(environ) 30 request = Request(environ)