changeset 19:afd11b758da0

just require genshi for now
author Jeff Hammel <jhammel@mozilla.com>
date Wed, 27 Oct 2010 09:09:37 -0700
parents 7800c6553c77
children 32a05d7bb214
files contenttransformer/transformers.py setup.py
diffstat 2 files changed, 25 insertions(+), 26 deletions(-) [+]
line wrap: on
line diff
--- a/contenttransformer/transformers.py
+++ b/contenttransformer/transformers.py
@@ -1,13 +1,16 @@
 import docutils.core
 import subprocess
 from utils import import_path
 from webob import Request, Response
 
+import genshi
+from genshi.template import MarkupTemplate
+
 class Transformer(object):
     """abstract base class for transformer objects"""
     def __init__(self, content, content_type):
         self.content = content
         self.content_type = content_type
 
     def transform(self, request):
         """returns a tuple of (body, content-type)"""
@@ -55,33 +58,28 @@ class RestructuredText(Transformer):
 
     def transform(self, request):
         """template: genshi(?) template to use (???)"""
         html = docutils.core.publish_string(self.content,
                                             writer_name='html',
                                             settings_overrides=self.settings)
         return ('text/html', html)
 
-try:
-    import genshi
-    from genshi.template import MarkupTemplate
 
-    class GenshiTransformer(Transformer):
+class GenshiTransformer(Transformer):
 
-        def __init__(self, content, content_type, modules=()):
-            """
-            - modules : strings of modules
-            """
-            self.variables = {}
-            for path in modules:
-                module = import_path(path)
-                name = path.rsplit('.')[-1]
-                self.variables[name] = module
-            Transformer.__init__(self, content, content_type)
+    def __init__(self, content, content_type, modules=()):
+        """
+        - modules : strings of modules
+        """
+        self.variables = {}
+        for path in modules:
+            module = import_path(path)
+            name = path.rsplit('.')[-1]
+            self.variables[name] = module
+        Transformer.__init__(self, content, content_type)
         
-        def transform(self, request):
-            variables = dict(request=request)
-            template = MarkupTemplate(self.content)
-            stream = template.generate(**variables)
-            return ('text/html', stream.render('html', doctype='html'))
+    def transform(self, request):
+        variables = dict(request=request)
+        template = MarkupTemplate(self.content)
+        stream = template.generate(**variables)
+        return ('text/html', stream.render('html', doctype='html'))
 
-except ImportError:
-    pass
--- a/setup.py
+++ b/setup.py
@@ -1,32 +1,33 @@
 from setuptools import setup, find_packages
 import sys, os
 
-version = "0.3.1"
+version = "0.3.2"
 
 setup(name='contenttransformer',
       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',
       author_email='k0scist@gmail.com',
       url='http://k0s.org/hg/contenttransformer',
       license="GPL",
       packages=find_packages(exclude=['ez_setup', 'examples', 'tests']),
       include_package_data=True,
       zip_safe=False,
       install_requires=[
           # -*- Extra requirements: -*-
-         'WebOb',	
-         'Paste',
-         'PasteScript',
-         'docutils'
+        'WebOb',	
+        'Paste',
+        'PasteScript',
+        'docutils',
+        'genshi',
       ],
       entry_points="""
       # -*- Entry points: -*-
       [paste.app_factory]
       main = contenttransformer.factory:factory
 
       [content_transformers]
       Graphviz = contenttransformer.transformers:Graphviz