Mercurial > hg > contenttransformer
changeset 1:aa491070ccf3
now works, just doesnt do anything, i dont think
author | k0s <k0scist@gmail.com> |
---|---|
date | Wed, 13 Jan 2010 23:58:13 -0500 |
parents | 29805d442afc |
children | 1e2c475015d8 |
files | contenttransformer/app.py contenttransformer/factory.py contenttransformer/web.py example.ini example/news.txt setup.py |
diffstat | 6 files changed, 28 insertions(+), 18 deletions(-) [+] |
line wrap: on
line diff
--- a/contenttransformer/app.py Mon Jan 11 11:32:24 2010 -0500 +++ b/contenttransformer/app.py Wed Jan 13 23:58:13 2010 -0500 @@ -10,12 +10,16 @@ def __init__(self, *types, **kwargs): """types is a list of two-tuples: glob pattern (string), transformer name (string, name of entry point)""" self.types = types - self.kwargs = kwargs # intended to be arguments to the xformers - for blah in iter_entry_points('content_transformers'): + + # intended to be arguments to the xformers + # XXX unused + self.kwargs = kwargs + + for entry_point in iter_entry_points('content_transformers'): try: - self.transformers['foo'] = entry_point.load() + self.transformers[entry_point.name] = entry_point.load() except: - raise + raise # XXX for pattern, transformer_name in self.types: assert transformer_name in self.transformers
--- a/contenttransformer/factory.py Mon Jan 11 11:32:24 2010 -0500 +++ b/contenttransformer/factory.py Wed Jan 13 23:58:13 2010 -0500 @@ -1,9 +1,9 @@ -from dispatcher import Dispatcher +from web import Dispatcher from paste.httpexceptions import HTTPExceptionHandler def factory(global_conf, **app_conf): """create a webob view and wrap it in middleware""" - keystr = 'typetransformer.' + keystr = 'transformer.' args = dict([(key.split(keystr, 1)[-1], value) for key, value in app_conf.items() if key.startswith(keystr) ])
--- a/contenttransformer/web.py Mon Jan 11 11:32:24 2010 -0500 +++ b/contenttransformer/web.py Wed Jan 13 23:58:13 2010 -0500 @@ -19,17 +19,17 @@ 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) + self.transformer = 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 = + path = os.path.join(self.directory, request.path_info.strip('/')) + if os.path.exists(path) and os.path.isfile(path): + handler = self.transformer(path) + return handler(environ, start_response) else: - handler = exc.HTTPNotFound() - pass # TODO: if self.app ... - return res(environ, start_response) + # TODO: if self.app ... + return exc.HTTPNotFound()(environ, start_response)
--- a/example.ini Mon Jan 11 11:32:24 2010 -0500 +++ b/example.ini Wed Jan 13 23:58:13 2010 -0500 @@ -13,10 +13,10 @@ [composite:main] use = egg:Paste#urlmap -/ = typetransformer +/ = contenttransformer set debug = false -[app:typetransformer] -paste.app_factory = typetransformer.factory:factory -typetransformer.directory = %(here)s/example +[app:contenttransformer] +paste.app_factory = contenttransformer.factory:factory +transformer.directory = %(here)s/example
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/example/news.txt Wed Jan 13 23:58:13 2010 -0500 @@ -0,0 +1,5 @@ +Phrase *actually* heard on the radio: + + ``...the Nigerian student with explosives in his underpants...`` + +I mean, okay, yeah, its serious. And its an apt description. But....wait, I can't even finish that sentence \ No newline at end of file
--- a/setup.py Mon Jan 11 11:32:24 2010 -0500 +++ b/setup.py Wed Jan 13 23:58:13 2010 -0500 @@ -21,6 +21,7 @@ 'WebOb', 'Paste', 'PasteScript', + 'docutils' ], entry_points=""" # -*- Entry points: -*- @@ -29,7 +30,7 @@ [content_transformers] Graphviz = contenttransformer.transformers:Graphviz - ReST = contenttransformer.transformers.RestructuredText + ReST = contenttransformer.transformers:RestructuredText """, )