Skip to content

Commit

Permalink
hide unwanted tracebacks in debugerror (idea from py.test)
Browse files Browse the repository at this point in the history
  • Loading branch information
anandology committed Nov 7, 2009
1 parent 5dd4292 commit 6561539
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 14 deletions.
30 changes: 16 additions & 14 deletions web/debugerror.py
Expand Up @@ -162,7 +162,7 @@
$for frame in frames:
<li class="frame">
<code>$frame.filename</code> in <code>$frame.function</code>
$if frame.context_line:
$if frame.context_line is not None:
<div class="context" id="c$frame.id">
$if frame.pre_context:
<ol start="$frame.pre_context_lineno" class="pre-context" id="pre$frame.id">
Expand Down Expand Up @@ -245,7 +245,7 @@ def _get_lines_from_file(filename, lineno, context_lines):
[line.strip('\n') for line in source[lineno + 1:upper_bound]]

return lower_bound, pre_context, context_line, post_context
except (OSError, IOError):
except (OSError, IOError, IndexError):
return None, [], None, []

exception_type, exception_value, tback = sys.exc_info()
Expand All @@ -256,18 +256,20 @@ def _get_lines_from_file(filename, lineno, context_lines):
lineno = tback.tb_lineno - 1
pre_context_lineno, pre_context, context_line, post_context = \
_get_lines_from_file(filename, lineno, 7)
frames.append(web.storage({
'tback': tback,
'filename': filename,
'function': function,
'lineno': lineno,
'vars': tback.tb_frame.f_locals,
'id': id(tback),
'pre_context': pre_context,
'context_line': context_line,
'post_context': post_context,
'pre_context_lineno': pre_context_lineno,
}))

if '__hidetraceback__' not in tback.tb_frame.f_locals:
frames.append(web.storage({
'tback': tback,
'filename': filename,
'function': function,
'lineno': lineno,
'vars': tback.tb_frame.f_locals,
'id': id(tback),
'pre_context': pre_context,
'context_line': context_line,
'post_context': post_context,
'pre_context_lineno': pre_context_lineno,
}))
tback = tback.tb_next
frames.reverse()
urljoin = urlparse.urljoin
Expand Down
3 changes: 3 additions & 0 deletions web/template.py
Expand Up @@ -777,11 +777,13 @@ def _compile(self, code):
return env['wrapper']

def __call__(self, *a, **kw):
__hidetraceback__ = True
t = self.t()
out = t(*a, **kw)
return self._join_output(out)

def _join_output(self, out):
__hidetraceback__ = True
d = TemplateResult()
data = []

Expand Down Expand Up @@ -862,6 +864,7 @@ def normalize_text(text):
normalize_text = staticmethod(normalize_text)

def __call__(self, *a, **kw):
__hidetraceback__ = True
import webapi as web
if 'headers' in web.ctx and self.content_type:
web.header('Content-Type', self.content_type, unique=True)
Expand Down

0 comments on commit 6561539

Please sign in to comment.