From 04e8f764e511bd0106bbc082c118e618a0b9b537 Mon Sep 17 00:00:00 2001 From: Adrien Di Mascio Date: Tue, 20 Jan 2009 12:06:52 +0100 Subject: add a new colorize_source function in debugger.py (based on ipython) --- debugger.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/debugger.py b/debugger.py index 3b6e433..e401a0f 100644 --- a/debugger.py +++ b/debugger.py @@ -28,9 +28,13 @@ except ImportError: def colorize(source, *args): """fallback colorize function""" return source + def colorize_source(source, *args): + return source else: def colorize(source, start_lineno, curlineno): - """""" + """colorize and annotate source with linenos + (as in pdb's list command) + """ parser = PyColorize.Parser() output = StringIO() parser.format(source, output) @@ -43,6 +47,14 @@ else: annotated.append('%4s\t\t%s' % (lineno, line)) return '\n'.join(annotated) + def colorize_source(source): + """colorize given source""" + parser = PyColorize.Parser() + output = StringIO() + parser.format(source, output) + return output.getvalue() + + def getsource(obj): """Return the text of the source code for an object. -- cgit v1.2.1