Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

hide unwanted tracebacks in debugerror (idea from py.test)

  • Loading branch information...
commit 6561539075bb854f4edc3e8e9e17c982645f1e44 1 parent 5dd4292
@anandology anandology authored
Showing with 19 additions and 14 deletions.
  1. +16 −14 web/debugerror.py
  2. +3 −0  web/template.py
View
30 web/debugerror.py
@@ -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">
@@ -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()
@@ -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
View
3  web/template.py
@@ -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 = []
@@ -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)
Please sign in to comment.
Something went wrong with that request. Please try again.