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
+++ b/contenttransformer/app.py
@@ -5,22 +5,26 @@ from paste.fileapp import FileApp
 from pkg_resources import iter_entry_points
 
 class FileTypeTransformer(object):
     transformers = {}
 
     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
 
     def __call__(self, path):
         """this should return something that is callable with (environ, start_response) to return a response; the transformer thing"""
         filename = os.path.basename(path)
         for pattern, transformer_name in self.types:
             if fnmatch(filename, pattern):
--- a/contenttransformer/factory.py
+++ b/contenttransformer/factory.py
@@ -1,12 +1,12 @@
-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) ])
     app = Dispatcher(**args)
     return HTTPExceptionHandler(app)
     
--- a/contenttransformer/web.py
+++ b/contenttransformer/web.py
@@ -14,22 +14,22 @@ class Dispatcher(object):
                  '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)
+        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
+++ b/example.ini
@@ -8,15 +8,15 @@ error_email_from = paste@localhost
 
 [server:main]
 use = egg:Paste#http
 host = 0.0.0.0
 port = 6666
 
 [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
new file mode 100644
--- /dev/null
+++ b/example/news.txt
@@ -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
+++ b/setup.py
@@ -16,20 +16,21 @@ setup(name='contentransformer',
       packages=find_packages(exclude=['ez_setup', 'examples', 'tests']),
       include_package_data=True,
       zip_safe=False,
       install_requires=[
           # -*- Extra requirements: -*-
          'WebOb',	
          'Paste',
          'PasteScript',
+         'docutils'
       ],
       entry_points="""
       # -*- Entry points: -*-
       [paste.app_factory]
       main = contenttransformer.factory:factory
 
       [content_transformers]
       Graphviz = contenttransformer.transformers:Graphviz
-      ReST = contenttransformer.transformers.RestructuredText
+      ReST = contenttransformer.transformers:RestructuredText
       """,
       )