Skip to content

bpo-33256: Replace square brackets around python object repr to display it in html #6442

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

Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions Lib/cgitb.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def html(einfo, context=5):
args, varargs, varkw, locals = inspect.getargvalues(frame)
call = ''
if func != '?':
call = 'in ' + strong(func) + \
call = 'in ' + strong(pydoc.html.escape(func)) + \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use pydoc.html.escape() also in line 285.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line 285 is not modified by the patch but I agree it's good to reuse pydoc.html.escape() there.
I committed the requested change.

inspect.formatargvalues(args, varargs, varkw, locals,
formatvalue=lambda value: '=' + pydoc.html.repr(value))

Expand Down Expand Up @@ -282,7 +282,7 @@ def handle(self, info=None):

if self.display:
if plain:
doc = doc.replace('&', '&amp;').replace('<', '&lt;')
doc = pydoc.html.escape(doc)
self.file.write('<pre>' + doc + '</pre>\n')
else:
self.file.write(doc + '\n')
Expand Down
1 change: 1 addition & 0 deletions Lib/test/test_cgitb.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ def test_syshook_no_logdir_default_format(self):
out = out.decode(sys.getfilesystemencoding())
self.assertIn("ValueError", out)
self.assertIn("Hello World", out)
self.assertIn("<strong>&lt;module&gt;</strong>", out)
# By default we emit HTML markup.
self.assertIn('<p>', out)
self.assertIn('</p>', out)
Expand Down
1 change: 1 addition & 0 deletions Misc/ACKS
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ Mike Bland
Martin Bless
Pablo Bleyer
Erik van Blokland
Stéphane Blondon
Eric Blossom
Sergey Bobrov
Finn Bock
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix display of ``<module>`` call in the html produced by ``cgitb.html()``. Patch by Stéphane Blondon.