summaryrefslogtreecommitdiff
path: root/paste/evalexception
diff options
context:
space:
mode:
authorianb <devnull@localhost>2005-11-17 02:32:24 +0000
committerianb <devnull@localhost>2005-11-17 02:32:24 +0000
commit03b1fb013bf7c58747842530944543a0fe427820 (patch)
tree86813a2331e432b312b4f04219e3bcdbe914cf30 /paste/evalexception
parentec5dc5adcdee8867af073468a719b2d3442114f6 (diff)
downloadpaste-03b1fb013bf7c58747842530944543a0fe427820.tar.gz
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)
Diffstat (limited to 'paste/evalexception')
-rw-r--r--paste/evalexception/media/debug.js12
-rw-r--r--paste/evalexception/middleware.py48
2 files changed, 33 insertions, 27 deletions
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 '<html>There was an error: %s</html>' % e
+ return '<html>There was an error: %s</html>' % 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 +
' <a href="#" class="switch_source" '
- 'framecount="%s" onClick="return showFrame(this)">&nbsp; &nbsp; '
+ 'tbid="%s" onClick="return showFrame(this)">&nbsp; &nbsp; '
'<img src="%s/_debug/media/plus.jpg" border=0 width=9 '
'height=9> &nbsp; &nbsp;</a>'
- % (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):
</form>''' % (url, '\n'.join(fields))
-def input_form(framecount, debug_info):
+def input_form(tbid, debug_info):
return '''
<form action="#" method="POST"
- onsubmit="return submitInput($(\'submit_%(framecount)s\'), %(framecount)s)">
-<div id="exec-output-%(framecount)s" style="width: 95%%;
+ onsubmit="return submitInput($(\'submit_%(tbid)s\'), %(tbid)s)">
+<div id="exec-output-%(tbid)s" style="width: 95%%;
padding: 5px; margin: 5px; border: 2px solid #000;
display: none"></div>
-<input type="text" name="input" id="debug_input_%(framecount)s"
+<input type="text" name="input" id="debug_input_%(tbid)s"
style="width: 100%%"
autocomplete="off" onkeypress="upArrow(this, event)"><br>
<input type="submit" value="Execute" name="submitbutton"
- onclick="return submitInput(this, %(framecount)s)"
- id="submit_%(framecount)s"
- input-from="debug_input_%(framecount)s"
- output-to="exec-output-%(framecount)s">
+ onclick="return submitInput(this, %(tbid)s)"
+ id="submit_%(tbid)s"
+ input-from="debug_input_%(tbid)s"
+ output-to="exec-output-%(tbid)s">
<input type="submit" value="Expand"
onclick="return expandInput(this)">
</form>
- ''' % {'framecount': framecount}
+ ''' % {'tbid': tbid}
error_template = '''
<html>