Mercurial > hg > SimpleWiki
comparison simplewiki/dispatcher.py @ 4:dd1c4916cbcd
[mq]: fileserver
author | Jeff Hammel <jhammel@mozilla.com> |
---|---|
date | Tue, 07 Sep 2010 22:39:15 -0700 |
parents | 56ab6b90cd1a |
children | b2fbb4f982da |
comparison
equal
deleted
inserted
replaced
3:56ab6b90cd1a | 4:dd1c4916cbcd |
---|---|
3 data persisting across requests should go here | 3 data persisting across requests should go here |
4 """ | 4 """ |
5 | 5 |
6 import os | 6 import os |
7 | 7 |
8 from handlers import GenshiRenderer, Index, Post | 8 from handlers import GenshiRenderer, Index, Post, FileServer |
9 | 9 |
10 from genshi.template import TemplateLoader | 10 from genshi.template import TemplateLoader |
11 from paste.fileapp import FileApp | 11 from paste.fileapp import FileApp |
12 from pkg_resources import resource_filename | 12 from pkg_resources import resource_filename |
13 from webob import Request, Response, exc | 13 from webob import Request, Response, exc |
28 self.auto_reload = self.auto_reload.lower() == 'true' | 28 self.auto_reload = self.auto_reload.lower() == 'true' |
29 | 29 |
30 assert self.directory and os.path.exists(self.directory), "Must specify an existing directory" | 30 assert self.directory and os.path.exists(self.directory), "Must specify an existing directory" |
31 | 31 |
32 # request handlers | 32 # request handlers |
33 self.handlers = [ Post, GenshiRenderer, Index ] | 33 self.handlers = [ Post, GenshiRenderer, Index, FileServer ] |
34 | 34 |
35 # template loader | 35 # template loader |
36 self.template_dirs = self.template_dirs.split() | 36 self.template_dirs = self.template_dirs.split() |
37 self.template_dirs.append(resource_filename(__name__, 'templates')) | 37 self.template_dirs.append(resource_filename(__name__, 'templates')) |
38 self.loader = TemplateLoader(self.template_dirs, | 38 self.loader = TemplateLoader(self.template_dirs, |
55 if handler is not None: | 55 if handler is not None: |
56 break | 56 break |
57 else: | 57 else: |
58 handler = exc.HTTPNotFound | 58 handler = exc.HTTPNotFound |
59 | 59 |
60 # add navigation links to handler [example] | |
61 if hasattr(handler, 'data'): | |
62 handler.data.setdefault('links', []) | |
63 for h in self.handlers: | |
64 handler.data['links'].append((handler.link(h.handler_path), | |
65 h.__name__)) | |
66 | |
67 # get response | 60 # get response |
68 res = handler() | 61 res = handler() |
69 return res(environ, start_response) | 62 return res(environ, start_response) |