Attachment 'colorer.py'
Download 1 """
2 MoinMoin - parser for Syntax Highlighting using the
3 http://colorer.sf.net
4 by
5 belugin@mail.ru
6
7 based on
8
9 MoinMoin - Processor for Syntax Highlighting using the enscript
10
11 Copyright (c) 2002 by Won-Kyu Park <wkpark@kldp.org>
12 All rights reserved, see COPYING for details.
13
14 $Id$
15
16 Usage:
17 {{{#!colorer sql
18 select * from testTable where a='test string'
19 }}}
20 """
21 import os,re,string,sys,popen2
22 Dependencies = ["time"]
23
24 class Parser:
25 def __init__(self, raw, request, **kw):
26 # save call arguments for later use in format
27 self.raw = raw
28 self.request = request
29 self.kw= kw
30
31 def format(self, formatter):
32 #type to pass to colorer
33 type=string.strip(self.kw['format_args'])
34 options='-dh -h -t%s' % type
35 cmd = 'colorer ' + options
36 try:
37 fromchild, tochild = popen2.popen4(cmd)
38 tochild.write(self.raw)
39 tochild.flush()
40 tochild.close()
41 fromchild.flush()
42 html = fromchild.readlines()
43 finally:
44 fromchild.close()
45
46 html=html[2:-4]
47 html='<PRE>'+string.join(html, '')+'</PRE>'
48
49 self.request.write(formatter.rawHTML(html))
Attached Files
To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.You are not allowed to attach a file to this page.