Mercurial > hg > contenttransformer
view 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 |
line wrap: on
line source
""" example app for how to use TypedTransformer TTW on a directory """ import os from contenttransformer.app import FileTypeTransformer from webob import Request, exc class Dispatcher(object): ### class level variables defaults = { 'app': None, 'directory': None, 'transforms': ''} def __init__(self, **kw): for key in self.defaults: setattr(self, key, kw.get(key, self.defaults[key])) assert os.path.exists(self.directory) self.transforms = [ [j.strip() for j in i.split('=', 1) ] for i in self.transforms.split(',') if '=' in i] self.handler = FileTypeTransformer(*self.transforms) if self.app: assert hasattr(self.app, '__call__') ### methods dealing with HTTP def __call__(self, environ, start_response): request = Request(environ) path = os.path.join(self.directory, request.path_info) if os.path.exists(path): handler = else: handler = exc.HTTPNotFound() pass # TODO: if self.app ... return res(environ, start_response)