summaryrefslogtreecommitdiff
path: root/paste/exceptions/collector.py
diff options
context:
space:
mode:
authorianb <devnull@localhost>2005-11-04 00:48:57 +0000
committerianb <devnull@localhost>2005-11-04 00:48:57 +0000
commit76c4d49ec1fa88847494dc2f7b01325a9a9dc9ca (patch)
treec9f0e06ced268f20fcc86fc5ed608ea9100d2083 /paste/exceptions/collector.py
parentb9bebe8c546228dbd18fd34b46207c10d8833c53 (diff)
downloadpaste-76c4d49ec1fa88847494dc2f7b01325a9a9dc9ca.tar.gz
Improve the error output, a little more compact with expandable source
Diffstat (limited to 'paste/exceptions/collector.py')
-rw-r--r--paste/exceptions/collector.py10
1 files changed, 8 insertions, 2 deletions
diff --git a/paste/exceptions/collector.py b/paste/exceptions/collector.py
index 8a92a9c..d136a9d 100644
--- a/paste/exceptions/collector.py
+++ b/paste/exceptions/collector.py
@@ -447,15 +447,21 @@ class ExceptionFrame(Bunch):
# The value of __traceback_hide__
traceback_hide = False
- def get_source_line(self):
+ def get_source_line(self, context=0):
"""
Return the source of the current line of this frame. You
probably want to .strip() it as well, as it is likely to have
leading whitespace.
+
+ If context is given, then that many lines on either side will
+ also be returned. E.g., context=1 will give 3 lines.
"""
if not self.filename or not self.lineno:
return None
- return linecache.getline(self.filename, self.lineno)
+ lines = []
+ for lineno in range(self.lineno-context, self.lineno+context+1):
+ lines.append(linecache.getline(self.filename, lineno))
+ return ''.join(lines)
if hasattr(sys, 'tracebacklimit'):
limit = min(limit, sys.tracebacklimit)