summaryrefslogtreecommitdiff
path: root/paste/evalexception
diff options
context:
space:
mode:
authorianb <devnull@localhost>2005-12-05 09:26:15 +0000
committerianb <devnull@localhost>2005-12-05 09:26:15 +0000
commit229f197a9cacea3892f3b4a042d72ddb83464cae (patch)
treece22d54fbc11bbf70212dffe2461a34dcfc120b7 /paste/evalexception
parentc6944a849d21424c4ff68c70d46fc7c325a2dfa0 (diff)
downloadpaste-229f197a9cacea3892f3b4a042d72ddb83464cae.tar.gz
Put in reduced-content exceptions for XMLHttpRequest responses, marked by the presence of a _ GET variable
Diffstat (limited to 'paste/evalexception')
-rw-r--r--paste/evalexception/evalcontext.py5
-rw-r--r--paste/evalexception/middleware.py28
2 files changed, 25 insertions, 8 deletions
diff --git a/paste/evalexception/evalcontext.py b/paste/evalexception/evalcontext.py
index 2b96126..5ce311d 100644
--- a/paste/evalexception/evalcontext.py
+++ b/paste/evalexception/evalcontext.py
@@ -17,8 +17,9 @@ class EvalContext(object):
doctest.
"""
- def __init__(self, namespace):
+ def __init__(self, namespace, globs):
self.namespace = namespace
+ self.globs = globs
def exec_expr(self, s):
out = StringIO()
@@ -31,7 +32,7 @@ class EvalContext(object):
sys.stdout = out
try:
code = compile(s, '<web>', "single", 0, 1)
- exec code in self.namespace
+ exec code in self.namespace, self.globs
debugger.set_continue()
except KeyboardInterrupt:
raise
diff --git a/paste/evalexception/middleware.py b/paste/evalexception/middleware.py
index 69b5c44..6c10f08 100644
--- a/paste/evalexception/middleware.py
+++ b/paste/evalexception/middleware.py
@@ -142,9 +142,13 @@ debug_counter = itertools.count(int(time.time()))
class EvalException(object):
- def __init__(self, application, global_conf=None):
+ def __init__(self, application, global_conf=None,
+ xmlhttp_key=None):
self.application = application
self.debug_infos = {}
+ if xmlhttp_key is None:
+ xmlhttp_key = global_conf.get('xmlhttp_key', '_')
+ self.xmlhttp_key = xmlhttp_key
def __call__(self, environ, start_response):
assert not environ['wsgi.multiprocess'], (
@@ -203,7 +207,8 @@ class EvalException(object):
input = input.rstrip() + '\n'
frame = debug_info.frame(int(tbid))
vars = frame.tb_frame.f_locals
- context = evalcontext.EvalContext(vars)
+ glob_vars = frame.tb_frame.f_globals
+ context = evalcontext.EvalContext(vars, glob_vars)
output = context.exec_expr(input)
input_html = formatter.str2html(input)
return ('<code style="color: #060">&gt;&gt;&gt;</code> '
@@ -233,14 +238,25 @@ class EvalException(object):
for expected in environ.get('paste.expected_exceptions', []):
if issubclass(exc_info[0], expected):
raise
- count = debug_counter.next()
- debug_info = DebugInfo(count, exc_info)
- assert count not in self.debug_infos
- self.debug_infos[count] = debug_info
+
if not started:
start_response('500 Internal Server Error',
[('content-type', 'text/html')],
exc_info)
+
+ if self.xmlhttp_key:
+ get_vars = wsgilib.parse_querystring(environ)
+ if dict(get_vars).get(self.xmlhttp_key):
+ exc_data = collector.collect_exception(*exc_info)
+ html = formatter.format_html(
+ exc_data, include_hidden_frames=False,
+ include_reusable=False, show_extra_data=False)
+ return [html]
+
+ count = debug_counter.next()
+ debug_info = DebugInfo(count, exc_info)
+ assert count not in self.debug_infos
+ self.debug_infos[count] = debug_info
# @@: it would be nice to deal with bad content types here
exc_data = collector.collect_exception(*exc_info)
html = format_eval_html(exc_data, base_path, count)