Mercurial > hg > contenttransformer
comparison contenttransformer/web.py @ 0:29805d442afc
initial commit of contenttransformer; still in the stub stage
author | k0s <k0scist@gmail.com> |
---|---|
date | Mon, 11 Jan 2010 11:32:24 -0500 |
parents | |
children | aa491070ccf3 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:29805d442afc |
---|---|
1 """ | |
2 example app for how to use TypedTransformer TTW on a directory | |
3 """ | |
4 | |
5 import os | |
6 | |
7 from contenttransformer.app import FileTypeTransformer | |
8 from webob import Request, exc | |
9 | |
10 class Dispatcher(object): | |
11 | |
12 ### class level variables | |
13 defaults = { 'app': None, | |
14 'directory': None, | |
15 'transforms': ''} | |
16 | |
17 def __init__(self, **kw): | |
18 for key in self.defaults: | |
19 setattr(self, key, kw.get(key, self.defaults[key])) | |
20 assert os.path.exists(self.directory) | |
21 self.transforms = [ [j.strip() for j in i.split('=', 1) ] for i in self.transforms.split(',') if '=' in i] | |
22 self.handler = FileTypeTransformer(*self.transforms) | |
23 if self.app: | |
24 assert hasattr(self.app, '__call__') | |
25 | |
26 ### methods dealing with HTTP | |
27 def __call__(self, environ, start_response): | |
28 request = Request(environ) | |
29 path = os.path.join(self.directory, request.path_info) | |
30 if os.path.exists(path): | |
31 handler = | |
32 else: | |
33 handler = exc.HTTPNotFound() | |
34 pass # TODO: if self.app ... | |
35 return res(environ, start_response) |