From 03b1fb013bf7c58747842530944543a0fe427820 Mon Sep 17 00:00:00 2001 From: ianb Date: Thu, 17 Nov 2005 02:32:24 +0000 Subject: Added a tbid attribute to frame objects; simplify signature of format_source_line function (passing in frame object); fixed evalexception middleware when traceback lines are trimmed (was counting lines, and the count was off during trimming) --- paste/evalexception/media/debug.js | 12 +++++----- paste/evalexception/middleware.py | 48 +++++++++++++++++++++----------------- 2 files changed, 33 insertions(+), 27 deletions(-) (limited to 'paste/evalexception') diff --git a/paste/evalexception/media/debug.js b/paste/evalexception/media/debug.js index 64d47f2..57f9df3 100644 --- a/paste/evalexception/media/debug.js +++ b/paste/evalexception/media/debug.js @@ -1,5 +1,5 @@ function showFrame(anchor) { - var framecount = anchor.getAttribute('framecount'); + var tbid = anchor.getAttribute('tbid'); var expanded = anchor.expanded; if (expanded) { MochiKit.DOM.hideElement(anchor.expandedElement); @@ -11,11 +11,11 @@ function showFrame(anchor) { if (anchor.expandedElement) { MochiKit.DOM.showElement(anchor.expandedElement); _swapImage(anchor); - $('debug_input_'+framecount).focus(); + $('debug_input_'+tbid).focus(); return false; } var url = debug_base - + '/show_frame?framecount=' + framecount + + '/show_frame?tbid=' + tbid + '&debugcount=' + debug_count; var d = MochiKit.Async.doSimpleXMLHttpRequest(url); d.addCallbacks(function (data) { @@ -24,7 +24,7 @@ function showFrame(anchor) { el.innerHTML = data.responseText; anchor.expandedElement = el; _swapImage(anchor); - $('debug_input_'+framecount).focus(); + $('debug_input_'+tbid).focus(); }, function (error) { showError(error.req.responseText); }); @@ -41,7 +41,7 @@ function _swapImage(anchor) { el.src = debug_base + '/media/' + img; } -function submitInput(button, framecount) { +function submitInput(button, tbid) { var input = $(button.getAttribute('input-from')); var output = $(button.getAttribute('output-to')); var url = debug_base @@ -53,7 +53,7 @@ function submitInput(button, framecount) { } history.push(input.value); var vars = { - framecount: framecount, + tbid: tbid, debugcount: debug_count, input: input.value }; diff --git a/paste/evalexception/middleware.py b/paste/evalexception/middleware.py index 72f223b..e4b5794 100644 --- a/paste/evalexception/middleware.py +++ b/paste/evalexception/middleware.py @@ -135,7 +135,7 @@ def get_debug_info(func): return func(self, debug_info=debug_info, **form) except ValueError, e: form['headers']['status'] = '500 Server Error' - return 'There was an error: %s' % e + return 'There was an error: %s' % html_quote(e) return debug_info_replacement debug_counter = itertools.count(int(time.time())) @@ -184,24 +184,24 @@ class EvalException(object): #@wsgiapp() #@get_debug_info - def show_frame(self, framecount, debug_info, **kw): - frame = debug_info.frames[int(framecount)] + def show_frame(self, tbid, debug_info, **kw): + frame = debug_info.frame(int(tbid)) vars = frame.tb_frame.f_locals if vars: local_vars = make_table(vars) else: local_vars = 'No local vars' - return input_form(framecount, debug_info) + local_vars + return input_form(tbid, debug_info) + local_vars show_frame = wsgiapp()(get_debug_info(show_frame)) #@wsgiapp() #@get_debug_info - def exec_input(self, framecount, debug_info, input, **kw): + def exec_input(self, tbid, debug_info, input, **kw): if not input.strip(): return '' input = input.rstrip() + '\n' - frame = debug_info.frames[int(framecount)] + frame = debug_info.frame(int(tbid)) vars = frame.tb_frame.f_locals context = evalcontext.EvalContext(vars) output = context.exec_expr(input) @@ -307,24 +307,30 @@ class DebugInfo(object): tb = tb.tb_next n += 1 + def frame(self, tbid): + for frame in self.frames: + if id(frame) == tbid: + return frame + else: + raise ValueError, ( + "No frame by id %s found from %r" % (tbid, self.frames)) + class EvalHTMLFormatter(formatter.HTMLFormatter): def __init__(self, base_path, counter, **kw): super(EvalHTMLFormatter, self).__init__(**kw) self.base_path = base_path self.counter = counter - self.framecount = -1 - def format_source_line(self, filename, modname, lineno, name): + def format_source_line(self, filename, frame): line = formatter.HTMLFormatter.format_source_line( - self, filename, modname, lineno, name) - self.framecount += 1 + self, filename, frame) return (line + '     ' + 'tbid="%s" onClick="return showFrame(this)">    ' '    ' - % (self.framecount, self.base_path)) + % (frame.tbid, self.base_path)) def make_table(items): if isinstance(items, dict): @@ -401,25 +407,25 @@ def make_repost_button(environ): ''' % (url, '\n'.join(fields)) -def input_form(framecount, debug_info): +def input_form(tbid, debug_info): return '''
-
+ -
+ onclick="return submitInput(this, %(tbid)s)" + id="submit_%(tbid)s" + input-from="debug_input_%(tbid)s" + output-to="exec-output-%(tbid)s"> - ''' % {'framecount': framecount} + ''' % {'tbid': tbid} error_template = ''' -- cgit v1.2.1