summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Cramer <dcramer@gmail.com>2016-06-27 15:58:45 -0700
committerDavid Cramer <dcramer@gmail.com>2016-06-27 15:58:51 -0700
commit61291827033c352853a3f4aeb33386e8ee645344 (patch)
tree0ee6a81e80a7834002fa7412956331e61ade71af
parent6692a83674683962d4b61aa66171fc1f61e2cfa2 (diff)
downloadraven-61291827033c352853a3f4aeb33386e8ee645344.tar.gz
Enforce max length on lines of code (512 chars)
-rw-r--r--raven/utils/stacks.py25
1 files changed, 21 insertions, 4 deletions
diff --git a/raven/utils/stacks.py b/raven/utils/stacks.py
index cbb3284..6c17cad 100644
--- a/raven/utils/stacks.py
+++ b/raven/utils/stacks.py
@@ -62,15 +62,24 @@ def get_lines_from_file(filename, lineno, context_lines,
upper_bound = min(lineno + 1 + context_lines, len(source))
try:
- pre_context = [line.strip('\r\n') for line in source[lower_bound:lineno]]
+ pre_context = [
+ line.strip('\r\n')
+ for line in source[lower_bound:lineno]
+ ]
context_line = source[lineno].strip('\r\n')
- post_context = [line.strip('\r\n') for line in
- source[(lineno + 1):upper_bound]]
+ post_context = [
+ line.strip('\r\n')
+ for line in source[(lineno + 1):upper_bound]
+ ]
except IndexError:
# the file may have changed since it was loaded into memory
return None, None, None
- return pre_context, context_line, post_context
+ return (
+ slim_string(pre_context),
+ slim_string(context_line),
+ slim_string(post_context)
+ )
def label_from_frame(frame):
@@ -243,6 +252,14 @@ def slim_frame_data(frames, frame_allowance=25):
return frames
+def slim_string(value, length=512):
+ if not value:
+ return value
+ if len(value) > length:
+ return value[:length - 3] + '...'
+ return value[:length]
+
+
def get_stack_info(frames, transformer=transform, capture_locals=True,
frame_allowance=25):
"""