1
# -*- coding: utf-8 -*-
6
Render the traceback debugging page.
8
:copyright: (c) 2009 by the Werkzeug Team, see AUTHORS for more details.
9
:license: BSD, see LICENSE for more details.
12
from os.path import dirname, join
14
from werkzeug.templates import Template
17
def get_template(name):
18
return Template.from_file(join(dirname(__file__), 'shared', name),
19
unicode_mode=False, errors='ignore')
22
def load_resource(res):
24
f = file(join(dirname(__file__), 'shared', res))
33
t_body = get_template('body.tmpl')
34
t_codetable = get_template('codetable.tmpl')
35
t_vartable = get_template('vartable.tmpl')
38
def code_table(frame):
39
from werkzeug.debug.util import Namespace
41
lineno = frame['context_lineno']
42
if lineno is not None:
44
for l in frame['pre_context']:
45
lines.append(Namespace(mode='pre', lineno=lineno, code=l))
47
lines.append(Namespace(mode='cur', lineno=lineno,
48
code=frame['context_line']))
50
for l in frame['post_context']:
51
lines.append(Namespace(mode='post', lineno=lineno, code=l))
54
lines.append(Namespace(mode='cur', lineno=1,
55
code='Sourcecode not available'))
57
return t_codetable.render(lines=lines)
63
lines = pprint.pformat(x).splitlines()
69
line = line[:79] + '...'
74
if isinstance(var, dict) or hasattr(var, 'items'):
81
value = [(repr(key), safe_pformat(val)) for key, val in value]
84
elif isinstance(var, list):
89
value = [safe_pformat(item) for item in var]
96
return t_vartable.render(type=typ, value=value)
99
def debug_page(context):
100
tc = context.to_dict()
101
tc['var_table'] = var_table
102
tc['code_table'] = code_table
103
return t_body.render(tc)