Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

better performance #25744

Closed
wants to merge 4 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions Lib/cgitb.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,19 @@ def reset():
__UNDEF__ = [] # a special sentinel object
def small(text):
if text:
return '<small>' + text + '</small>'
return f'<small>{text}</small>'
else:
return ''

def strong(text):
if text:
return '<strong>' + text + '</strong>'
return f'<strong>{text}</strong>'
else:
return ''

def grey(text):
if text:
return '<font color="#909090">' + text + '</font>'
return f'<font color="#909090">{text}</font>'
else:
return ''

Expand Down Expand Up @@ -91,7 +91,7 @@ def scanvars(reader, frame, locals):
where, value = lookup(token, frame, locals)
vars.append((token, where, value))
elif token == '.':
prefix += lasttoken + '.'
prefix += f"{lasttoken}."
parent = value
else:
parent, prefix = None, ''
Expand All @@ -103,6 +103,7 @@ def html(einfo, context=5):
etype, evalue, etb = einfo
if isinstance(etype, type):
etype = etype.__name__
pyver = f'Python {sys.version.split()[0]}:{sys.executable}'
pyver = 'Python ' + sys.version.split()[0] + ': ' + sys.executable
date = time.ctime(time.time())
head = '<body bgcolor="#f0f0f8">' + pydoc.html.heading(
Expand Down Expand Up @@ -143,8 +144,8 @@ def reader(lnum=[lnum]):
for line in lines:
num = small('&nbsp;' * (5-len(str(i))) + str(i)) + '&nbsp;'
if i in highlight:
line = '<tt>=&gt;%s%s</tt>' % (num, pydoc.html.preformat(line))
rows.append('<tr><td bgcolor="#ffccee">%s</td></tr>' % line)
line = f'<tt>=&gt;{num}{pydoc.html.preformat(line)}</tt>'
rows.append(f'<tr><td bgcolor="#ffccee">{line}</td></tr>')
else:
line = '<tt>&nbsp;&nbsp;%s%s</tt>' % (num, pydoc.html.preformat(line))
rows.append('<tr><td>%s</td></tr>' % grey(line))
Expand All @@ -163,7 +164,7 @@ def reader(lnum=[lnum]):
name = where + strong(name.split('.')[-1])
dump.append('%s&nbsp;= %s' % (name, pydoc.html.repr(value)))
else:
dump.append(name + ' <em>undefined</em>')
dump.append(f'{name} <em>undefined</em>')

rows.append('<tr><td>%s</td></tr>' % small(grey(', '.join(dump))))
frames.append('''
Expand Down