[Moin-devel] CVS: MoinMoin/parser python.py,1.8,1.9
J?rgen Hermann
jhermann at users.sourceforge.net
Mon Mar 4 11:13:16 EST 2002
Update of /cvsroot/moin/MoinMoin/parser
In directory usw-pr-cvs1:/tmp/cvs-serv6443/parser
Modified Files:
python.py
Log Message:
Added linecounts to colorized code displays
Index: python.py
===================================================================
RCS file: /cvsroot/moin/MoinMoin/parser/python.py,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -r1.8 -r1.9
*** python.py 19 Feb 2002 23:08:26 -0000 1.8
--- python.py 4 Mar 2002 19:12:57 -0000 1.9
***************
*** 32,44 ****
class Parser:
""" Send colored python source.
"""
! def __init__(self, raw, **kw):
""" Store the source text.
"""
self.raw = string.rstrip(string.expandtabs(raw))
! self.out = kw.get('out', sys.stdout)
def format(self, formatter, form):
--- 32,94 ----
+ class CountedOutput:
+ """ Add line counts and possibly info texts to output
+ """
+
+ def __init__(self, out, lineinfo):
+ self.out = out
+ self.lineinfo = lineinfo
+ self.line = 0
+ self.infocounter = 0
+ self.maxinfo = 0
+
+ if lineinfo:
+ import operator
+ self.maxinfo = reduce(operator.add, map(len, lineinfo.values()), 0)
+
+ def line_no(self):
+ if self.lineinfo:
+ for info in self.lineinfo.get(self.line, []):
+ self.infocounter += 1
+ self.out.write('<a name="info%d"></a>'
+ '<b><font color="%s">' % (self.infocounter, '#FF0000'))
+ if self.infocounter == 1:
+ self.out.write(' ')
+ else:
+ self.out.write('<a href="#info%d"><<</a> ' % (self.infocounter-1))
+ if self.infocounter == self.maxinfo:
+ self.out.write(' ')
+ else:
+ self.out.write('<a href="#info%d">>></a> ' % (self.infocounter+1))
+ self.out.write('#%d: %s</font></b>\n' % (self.infocounter, info))
+ self.out.write('<font color="%s">%5d </font>' % (_colors[_TEXT], self.line))
+
+ def write(self, data):
+ if not self.line:
+ self.line = 1
+ self.line_no()
+
+ parts = data.split('\n')
+ if len(parts) > 1:
+ self.out.write(parts[0])
+ for part in parts[1:]:
+ self.line += 1
+ self.out.write('\n')
+ self.line_no()
+ self.out.write(part)
+ else:
+ self.out.write(data)
+
+
class Parser:
""" Send colored python source.
"""
! def __init__(self, raw, lineinfo={}, **kw):
""" Store the source text.
"""
self.raw = string.rstrip(string.expandtabs(raw))
! self.rawout = kw.get('out', sys.stdout)
! self.out = CountedOutput(self.rawout, lineinfo)
def format(self, formatter, form):
***************
*** 57,61 ****
self.pos = 0
text = cStringIO.StringIO(self.raw)
! self.out.write('<pre><font face="Lucida,Courier New">')
try:
tokenize.tokenize(text.readline, self)
--- 107,111 ----
self.pos = 0
text = cStringIO.StringIO(self.raw)
! self.rawout.write('<pre><font face="Lucida,Courier New">')
try:
tokenize.tokenize(text.readline, self)
***************
*** 63,69 ****
msg = ex[0]
line = ex[1][0]
! self.out.write("<h3>ERROR: %s</h3>%s\n" % (
msg, self.raw[self.lines[line]:]))
! self.out.write('</font></pre>')
def __call__(self, toktype, toktext, (srow,scol), (erow,ecol), line):
--- 113,119 ----
msg = ex[0]
line = ex[1][0]
! self.rawout.write("<h3>ERROR: %s</h3>%s\n" % (
msg, self.raw[self.lines[line]:]))
! self.rawout.write('</font></pre>')
def __call__(self, toktype, toktext, (srow,scol), (erow,ecol), line):
More information about the Moin-devel
mailing list