# HG changeset patch # User k0s # Date 1263445093 18000 # Node ID aa491070ccf36325673dbe7cc38534491a4d022d # Parent 29805d442afcf704ab0d85dbfece99cee5cba288 now works, just doesnt do anything, i dont think diff -r 29805d442afc -r aa491070ccf3 contenttransformer/app.py --- 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 diff -r 29805d442afc -r aa491070ccf3 contenttransformer/factory.py --- 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) ]) diff -r 29805d442afc -r aa491070ccf3 contenttransformer/web.py --- 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) diff -r 29805d442afc -r aa491070ccf3 example.ini --- 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 diff -r 29805d442afc -r aa491070ccf3 example/news.txt --- /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 diff -r 29805d442afc -r aa491070ccf3 setup.py --- 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 """, )