diff options
author | Adrien Di Mascio <Adrien.DiMascio@logilab.fr> | 2009-01-20 12:06:52 +0100 |
---|---|---|
committer | Adrien Di Mascio <Adrien.DiMascio@logilab.fr> | 2009-01-20 12:06:52 +0100 |
commit | 04e8f764e511bd0106bbc082c118e618a0b9b537 (patch) | |
tree | 6801e02f9a47cdb9a39fde8b52dc66d79f82dd2d | |
parent | 5af9c6201892c81db1c2efd0e2ba640248e52d49 (diff) | |
download | logilab-common-04e8f764e511bd0106bbc082c118e618a0b9b537.tar.gz |
add a new colorize_source function in debugger.py (based on ipython)
-rw-r--r-- | debugger.py | 14 |
1 files changed, 13 insertions, 1 deletions
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. |