summaryrefslogtreecommitdiff
path: root/Lib/cgitb.py
diff options
context:
space:
mode:
authorKa-Ping Yee <ping@zesty.ca>2002-06-26 07:10:56 +0000
committerKa-Ping Yee <ping@zesty.ca>2002-06-26 07:10:56 +0000
commit711cad769a60b4a53520bb1daf580d2ca252b450 (patch)
treed6bf6cd3d5b97bb47ea53a74a1579e8d59294449 /Lib/cgitb.py
parent763805dab2598cefb236727db255adb87bdda8fc (diff)
downloadcpython-git-711cad769a60b4a53520bb1daf580d2ca252b450.tar.gz
Also look up variable names in __builtins__ if not found in globals.
Don't show hidden fields of exception values (names starting with '_').
Diffstat (limited to 'Lib/cgitb.py')
-rw-r--r--Lib/cgitb.py18
1 files changed, 15 insertions, 3 deletions
diff --git a/Lib/cgitb.py b/Lib/cgitb.py
index 381fb7b8e7..b39fd936ef 100644
--- a/Lib/cgitb.py
+++ b/Lib/cgitb.py
@@ -42,6 +42,14 @@ def lookup(name, frame, locals):
return 'local', locals[name]
if name in frame.f_globals:
return 'global', frame.f_globals[name]
+ if '__builtins__' in frame.f_globals:
+ builtins = frame.f_globals['__builtins__']
+ if type(builtins) is type({}):
+ if name in builtins:
+ return 'builtin', builtins[name]
+ else:
+ if hasattr(builtins, name):
+ return 'builtin', getattr(builtins, name)
return None, __UNDEF__
def scanvars(reader, frame, locals):
@@ -118,9 +126,12 @@ function calls leading up to the error, in the order they occurred.'''
if name in done: continue
done[name] = 1
if value is not __UNDEF__:
- if where == 'global': name = '<em>global</em> ' + strong(name)
- elif where == 'local': name = strong(name)
- else: name = where + strong(name.split('.')[-1])
+ if where in ['global', 'builtin']:
+ name = ('<em>%s</em> ' % where) + strong(name)
+ elif where == 'local':
+ name = strong(name)
+ else:
+ name = where + strong(name.split('.')[-1])
dump.append('%s&nbsp;= %s' % (name, pydoc.html.repr(value)))
else:
dump.append(name + ' <em>undefined</em>')
@@ -133,6 +144,7 @@ function calls leading up to the error, in the order they occurred.'''
exception = ['<p>%s: %s' % (strong(str(etype)), str(evalue))]
if type(evalue) is types.InstanceType:
for name in dir(evalue):
+ if name[:1] == '_': continue
value = pydoc.html.repr(getattr(evalue, name))
exception.append('\n<br>%s%s&nbsp;=\n%s' % (indent, name, value))