# HG changeset patch # User Jeff Hammel # Date 1604429718 28800 # Node ID 9cf78a1c73739679df0d5c7a1e8e8bb83015c701 # Parent ee3eadc97a4186d6641a7f5d5ad4bd6d29a29832 python3 diff -r ee3eadc97a41 -r 9cf78a1c7373 contenttransformer/transformers.py --- a/contenttransformer/transformers.py Tue Nov 03 10:53:13 2020 -0800 +++ b/contenttransformer/transformers.py Tue Nov 03 10:55:18 2020 -0800 @@ -1,6 +1,6 @@ import docutils.core import subprocess -from utils import import_path +from .utils import import_path from webob import Request, Response import genshi @@ -35,14 +35,15 @@ def transform(self, request): return (self.to_type, self.content) + class Graphviz(Transformer): content_types = { 'png': 'image/png', 'svg': 'image/svg+xml' } - + def __init__(self, content, content_type, format='png'): self.format=format Transformer.__init__(self, content, content_type) - + def transform(self, request): """create a Graphviz object""" _format = request.GET.get('format', self.format) @@ -53,6 +54,7 @@ image, _ = process.communicate(self.content) return (self.content_types[_format], image) + class RestructuredText(Transformer): settings = { 'report_level': 5 } @@ -76,10 +78,9 @@ 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')) -