Mercurial > hg > contenttransformer
comparison contenttransformer/transformers.py @ 12:59496de89997
allow graphviz to serve svg
author | Jeff Hammel <jhammel@mozilla.com> |
---|---|
date | Wed, 30 Jun 2010 22:01:50 -0700 |
parents | a9ddcfc7c4e8 |
children | 946176949bba |
comparison
equal
deleted
inserted
replaced
11:ba52425d1250 | 12:59496de89997 |
---|---|
30 | 30 |
31 def transform(self, request): | 31 def transform(self, request): |
32 return (self.to_type, self.content) | 32 return (self.to_type, self.content) |
33 | 33 |
34 class Graphviz(Transformer): | 34 class Graphviz(Transformer): |
35 content_types = { 'png': 'image/png', | |
36 'svg': 'image/svg+xml' } | |
37 | |
38 def __init__(self, content, content_type, format='png'): | |
39 self.format=format | |
40 Transformer.__init__(self, content, content_type) | |
41 | |
35 def transform(self, request): | 42 def transform(self, request): |
36 """create a Graphviz object""" | 43 """create a Graphviz object""" |
37 process = subprocess.Popen(['dot', '-Tpng'], | 44 _format = request.GET.get('format', self.format) |
45 assert _format in self.content_types, 'Unknown format: ' + _format | |
46 process = subprocess.Popen(['dot', '-T' + _format], | |
38 stdin=subprocess.PIPE, | 47 stdin=subprocess.PIPE, |
39 stdout=subprocess.PIPE) | 48 stdout=subprocess.PIPE) |
40 image, _ = process.communicate(self.content) | 49 image, _ = process.communicate(self.content) |
41 return ('image/png', image) | 50 return (self.content_types[_format], image) |
42 | 51 |
43 class RestructuredText(Transformer): | 52 class RestructuredText(Transformer): |
44 settings = { 'report_level': 5 } | 53 settings = { 'report_level': 5 } |
45 | 54 |
46 def transform(self, request): | 55 def transform(self, request): |