dowski's projects - pysourcecolorfilter

pysourcecolorfilter

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

OVERVIEW:

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.

REQUIREMENTS:

CherryPy 2.1
PySourceColor 2.0

DETAILS:

Its constructor requires one argument, target, which can be either 'inline' or 'static', to colorize inline source code or colorize static .py files respectively.

INLINE:

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

STATIC:

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.

EXAMPLE:

See the example at the bottom of the code for sample usage.

TODO:

  • Modify the filter to do inline coloring of Python using CSS and not just HTML.
  • Modify the module to have two filters - ColorizeStatic and ColorizeInline.

Files:

pysourcecolorfilter-0.9.zip
pysourcecolorfilter.py [colorized]


Add Comment:

Commenting disabled because of spam problem...

Menu:

Home
Admin

Projects:

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

Tags:

wireless
wsgi
http
templating
cherrypy
ssl
python
plugins
module
win32
application
ajax
library
cheetah
myghty
filter
kid

Powered By: