# HG changeset patch # User Jeff Hammel # Date 1277960510 25200 # Node ID 59496de899977b00c000a2ab2a36b9ce99310f7f # Parent ba52425d12502aa77251acf93081252408b4338e allow graphviz to serve svg diff -r ba52425d1250 -r 59496de89997 contenttransformer/transformers.py --- a/contenttransformer/transformers.py Sun Feb 07 19:48:55 2010 -0500 +++ b/contenttransformer/transformers.py Wed Jun 30 22:01:50 2010 -0700 @@ -32,13 +32,22 @@ 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""" - process = subprocess.Popen(['dot', '-Tpng'], + _format = request.GET.get('format', self.format) + assert _format in self.content_types, 'Unknown format: ' + _format + process = subprocess.Popen(['dot', '-T' + _format], stdin=subprocess.PIPE, stdout=subprocess.PIPE) image, _ = process.communicate(self.content) - return ('image/png', image) + return (self.content_types[_format], image) class RestructuredText(Transformer): settings = { 'report_level': 5 }