annotate contenttransformer/transformers.py @ 3:1a267297f779

graphviz now works, giving real version
author k0s <k0scist@gmail.com>
date Thu, 14 Jan 2010 00:16:34 -0500
parents 1e2c475015d8
children 68643e72c749
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
29805d442afc initial commit of contenttransformer; still in the stub stage
k0s <k0scist@gmail.com>
parents:
diff changeset
1 import docutils.core
2
1e2c475015d8 restructured text now works
k0s <k0scist@gmail.com>
parents: 0
diff changeset
2 import subprocess
0
29805d442afc initial commit of contenttransformer; still in the stub stage
k0s <k0scist@gmail.com>
parents:
diff changeset
3 from webob import Response
29805d442afc initial commit of contenttransformer; still in the stub stage
k0s <k0scist@gmail.com>
parents:
diff changeset
4
29805d442afc initial commit of contenttransformer; still in the stub stage
k0s <k0scist@gmail.com>
parents:
diff changeset
5 class Graphviz(object):
29805d442afc initial commit of contenttransformer; still in the stub stage
k0s <k0scist@gmail.com>
parents:
diff changeset
6 def __init__(self, content):
29805d442afc initial commit of contenttransformer; still in the stub stage
k0s <k0scist@gmail.com>
parents:
diff changeset
7 """create a Graphviz object"""
3
1a267297f779 graphviz now works, giving real version
k0s <k0scist@gmail.com>
parents: 2
diff changeset
8 process = subprocess.Popen(['dot', '-Tpng'],
1a267297f779 graphviz now works, giving real version
k0s <k0scist@gmail.com>
parents: 2
diff changeset
9 stdin=subprocess.PIPE,
1a267297f779 graphviz now works, giving real version
k0s <k0scist@gmail.com>
parents: 2
diff changeset
10 stdout=subprocess.PIPE)
1a267297f779 graphviz now works, giving real version
k0s <k0scist@gmail.com>
parents: 2
diff changeset
11 self.image, _ = process.communicate(content)
0
29805d442afc initial commit of contenttransformer; still in the stub stage
k0s <k0scist@gmail.com>
parents:
diff changeset
12
29805d442afc initial commit of contenttransformer; still in the stub stage
k0s <k0scist@gmail.com>
parents:
diff changeset
13 def __call__(self, environ, start_response):
29805d442afc initial commit of contenttransformer; still in the stub stage
k0s <k0scist@gmail.com>
parents:
diff changeset
14 """return a WSGI response"""
3
1a267297f779 graphviz now works, giving real version
k0s <k0scist@gmail.com>
parents: 2
diff changeset
15 return Response(content_type='image/png', body=self.image)(environ, start_response)
0
29805d442afc initial commit of contenttransformer; still in the stub stage
k0s <k0scist@gmail.com>
parents:
diff changeset
16
29805d442afc initial commit of contenttransformer; still in the stub stage
k0s <k0scist@gmail.com>
parents:
diff changeset
17 class RestructuredText(object):
29805d442afc initial commit of contenttransformer; still in the stub stage
k0s <k0scist@gmail.com>
parents:
diff changeset
18 settings = { 'report_level': 5 }
29805d442afc initial commit of contenttransformer; still in the stub stage
k0s <k0scist@gmail.com>
parents:
diff changeset
19
29805d442afc initial commit of contenttransformer; still in the stub stage
k0s <k0scist@gmail.com>
parents:
diff changeset
20 def __init__(self, content):
29805d442afc initial commit of contenttransformer; still in the stub stage
k0s <k0scist@gmail.com>
parents:
diff changeset
21 """template: genshi(?) template to use (???)"""
29805d442afc initial commit of contenttransformer; still in the stub stage
k0s <k0scist@gmail.com>
parents:
diff changeset
22 self.html = docutils.core.publish_string(content,
29805d442afc initial commit of contenttransformer; still in the stub stage
k0s <k0scist@gmail.com>
parents:
diff changeset
23 writer_name='html',
29805d442afc initial commit of contenttransformer; still in the stub stage
k0s <k0scist@gmail.com>
parents:
diff changeset
24 settings_overrides=self.settings)
29805d442afc initial commit of contenttransformer; still in the stub stage
k0s <k0scist@gmail.com>
parents:
diff changeset
25
29805d442afc initial commit of contenttransformer; still in the stub stage
k0s <k0scist@gmail.com>
parents:
diff changeset
26 def __call__(self, environ, start_response):
29805d442afc initial commit of contenttransformer; still in the stub stage
k0s <k0scist@gmail.com>
parents:
diff changeset
27 """return a WSGI response"""
2
1e2c475015d8 restructured text now works
k0s <k0scist@gmail.com>
parents: 0
diff changeset
28 return Response(content_type='text/html', body=self.html)(environ, start_response)