changeset 13:9d51954e2e68

allow transformers to take kwargs
author Jeff Hammel <jhammel@mozilla.com>
date Wed, 30 Jun 2010 22:09:13 -0700
parents 59496de89997
children 7dae51af8db6
files contenttransformer/app.py
diffstat 1 files changed, 3 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/contenttransformer/app.py
+++ b/contenttransformer/app.py
@@ -7,18 +7,17 @@ from pkg_resources import iter_entry_poi
 from transformers import ContentTypeChanger
 
 class FileTypeTransformer(object):
 
     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
+        # arguments to the xformers
         self.kwargs = kwargs
         
         self.transformers = transformers()
         for pattern, transformer_name in self.types:
             if '/' in transformer_name:
                 continue
             assert transformer_name in self.transformers
 
@@ -29,18 +28,18 @@ class FileTypeTransformer(object):
             if fnmatch(filename, pattern):
                 content_type, _ = guess_type(filename)
                 content = file(path).read()
 
                 # transform content type
                 # XXX hack: -> refactor
                 if '/' in transformer_name:
                     return ContentTypeChanger(content, content_type, transformer_name)
-                    
-                return self.transformers[transformer_name](content, content_type)
+                
+                return self.transformers[transformer_name](content, content_type, **self.kwargs.get(transformer_name, {}))
         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()