changeset 4:5258325a496a

move transformers getting method to a standalone function
author k0s <k0scist@gmail.com>
date Sun, 17 Jan 2010 19:47:32 -0500
parents 1a267297f779
children 349a80ce9def
files contenttransformer/app.py setup.py
diffstat 2 files changed, 15 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/contenttransformer/app.py
+++ b/contenttransformer/app.py
@@ -1,33 +1,39 @@
 import os
 import sys
 from fnmatch import fnmatch
 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
 
         # intended to be arguments to the xformers
         # XXX unused
         self.kwargs = kwargs
-        
-        for entry_point in iter_entry_points('content_transformers'):
-            try:
-                self.transformers[entry_point.name] = entry_point.load()
-            except:
-                raise # XXX
+
+        self.transformers = transformers()
         for pattern, transformer_name in self.types:
             assert transformer_name in self.transformers
 
-    def __call__(self, path):
+    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):
                 content = file(path).read()
                 return self.transformers[transformer_name](content)
         return FileApp(path)
+
+
+def transformers():
+    transformers = {} # XXX could cache
+    for entry_point in iter_entry_points('content_transformers'):
+        try:
+            transformers[entry_point.name] = entry_point.load()
+        except:
+            raise # XXX
+    return transformers
+        
--- a/setup.py
+++ b/setup.py
@@ -1,12 +1,12 @@
 from setuptools import setup, find_packages
 import sys, os
 
-version = "0.1"
+version = "0.1.1"
 
 setup(name='contentransformer',
       version=version,
       description="transform e.g. file data based on type to be served TTW",
       long_description="""
 """,
       classifiers=[], # Get strings from http://www.python.org/pypi?%3Aaction=list_classifiers
       author='Jeff Hammel',