A filter to colorize Python source code using PySourceColor and CherryPy.
Created: 2006-02-13 | Updated: 2006-02-17 | Status: Active | Tags: python cherrypy filter
This filter uses M.E.Farmer's PySourceColor module and the builtin StaticFilter included with CherryPy to serve up colorized versions of Python source files. It can also do inline colorizing of code inside of "py" tags. It can be easily integrated into an existing CherryPy powered site to provide convenient colorized source access.
CherryPy 2.1
PySourceColor 2.0
Its constructor requires one argument, target, which can be either 'inline' or 'static', to colorize inline source code or colorize static .py files respectively.
To colorize inline, simply enclose your Python source code snippets in "py" tags. The "py" tags will be replaced with "pre" tags filled with colorized HTML (no CSS at the moment).
Here is an example:
import this
# here is a comment
## import twisted ;P
import cherrypy
def spam():
print "I'm spam"
for c in 'spam':
print c
For serving colorized versions of .py files, you need to select a
default version to be returned to the browser when a .py file is
requested. That is what the defaultVersion parameter is for in the
filter's constructor. Specify either 'colorized' or 'original'.
The version can be further specified per request via a query string
parameter. For example,
"http://localhost:8080/source/spam.py?version=original"
will request the original version of the file, whatever the default
may be.
See the example at the bottom of the code for sample usage.
pysourcecolorfilter-0.9.zip
pysourcecolorfilter.py
[colorized]
balloondemo
brockman
buffet
buffetmyghty
buffetstring
buffetxslt
cardinfo
cp22collection
cp22simple_ajax
cp_middleware_server
cpmyghty
excuses
iresponse
littlebrother
multiauth
phpfilter
pysourcecolorfilter
request2
simplebackend
stunnelfilter
wsgi_filter
wireless
wsgi
http
templating
cherrypy
ssl
python
plugins
module
win32
application
ajax
library
cheetah
myghty
filter
kid