Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5fcefdb

Browse files
committed
[Patch #987052 from Thomas Guettler]
Don't output empty tags Escape page header Remove <p> before <table> (tidy complains)
1 parent bf44069 commit 5fcefdb

1 file changed

Lines changed: 21 additions & 6 deletions

File tree

Lib/cgitb.py

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,23 @@ def reset():
3737
</table> </table> </table> </table> </table> </font> </font> </font>'''
3838

3939
__UNDEF__ = [] # a special sentinel object
40-
def small(text): return '<small>' + text + '</small>'
41-
def strong(text): return '<strong>' + text + '</strong>'
42-
def grey(text): return '<font color="#909090">' + text + '</font>'
40+
def small(text):
41+
if text:
42+
return '<small>' + text + '</small>'
43+
else:
44+
return ''
45+
46+
def strong(text):
47+
if text:
48+
return '<strong>' + text + '</strong>'
49+
else:
50+
return ''
51+
52+
def grey(text):
53+
if text:
54+
return '<font color="#909090">' + text + '</font>'
55+
else:
56+
return ''
4357

4458
def lookup(name, frame, locals):
4559
"""Find the value for a given name in the given environment."""
@@ -88,10 +102,11 @@ def html((etype, evalue, etb), context=5):
88102
pyver = 'Python ' + sys.version.split()[0] + ': ' + sys.executable
89103
date = time.ctime(time.time())
90104
head = '<body bgcolor="#f0f0f8">' + pydoc.html.heading(
91-
'<big><big><strong>%s</strong></big></big>' % str(etype),
105+
'<big><big>%s</big></big>' %
106+
strong(pydoc.html.escape(str(etype))),
92107
'#ffffff', '#6622aa', pyver + '<br>' + date) + '''
93108
<p>A problem occurred in a Python script. Here is the sequence of
94-
function calls leading up to the error, in the order they occurred.'''
109+
function calls leading up to the error, in the order they occurred.</p>'''
95110

96111
indent = '<tt>' + small('&nbsp;' * 5) + '&nbsp;</tt>'
97112
frames = []
@@ -142,7 +157,7 @@ def reader(lnum=[lnum]):
142157
dump.append(name + ' <em>undefined</em>')
143158

144159
rows.append('<tr><td>%s</td></tr>' % small(grey(', '.join(dump))))
145-
frames.append('''<p>
160+
frames.append('''
146161
<table width="100%%" cellspacing=0 cellpadding=0 border=0>
147162
%s</table>''' % '\n'.join(rows))
148163

0 commit comments

Comments
 (0)