[Python-checkins] bpo-33256: Replace angle brackets around python object repr to display it in html (GH-6442)

Miss Islington (bot) webhook-mailer at python.org
Sun Apr 29 15:10:15 EDT 2018


https://github.com/python/cpython/commit/736f17fb8d8b105567d56317f9c0b4c577ce4105
commit: 736f17fb8d8b105567d56317f9c0b4c577ce4105
branch: 3.7
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: GitHub <noreply at github.com>
date: 2018-04-29T12:10:12-07:00
summary:

bpo-33256: Replace angle brackets around python object repr to display it in html (GH-6442)

(cherry picked from commit 7d68bfa82654ba01d860b8a772ff63bf0bd183ee)

Co-authored-by: sblondon <sblondon at users.noreply.github.com>

files:
A Misc/NEWS.d/next/Library/2018-04-10-20-57-14.bpo-33256.ndHkqu.rst
M Lib/cgitb.py
M Lib/test/test_cgitb.py
M Misc/ACKS

diff --git a/Lib/cgitb.py b/Lib/cgitb.py
index b29110018cd1..0f5f32c0fade 100644
--- a/Lib/cgitb.py
+++ b/Lib/cgitb.py
@@ -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)) + \
                 inspect.formatargvalues(args, varargs, varkw, locals,
                     formatvalue=lambda value: '=' + pydoc.html.repr(value))
 
@@ -282,7 +282,7 @@ def handle(self, info=None):
 
         if self.display:
             if plain:
-                doc = doc.replace('&', '&').replace('<', '<')
+                doc = pydoc.html.escape(doc)
                 self.file.write('<pre>' + doc + '</pre>\n')
             else:
                 self.file.write(doc + '\n')
diff --git a/Lib/test/test_cgitb.py b/Lib/test/test_cgitb.py
index a87a4224f94d..e299ec3ec6ce 100644
--- a/Lib/test/test_cgitb.py
+++ b/Lib/test/test_cgitb.py
@@ -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><module></strong>", out)
         # By default we emit HTML markup.
         self.assertIn('<p>', out)
         self.assertIn('</p>', out)
diff --git a/Misc/ACKS b/Misc/ACKS
index 3cf1b9caa656..64262c490c66 100644
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -158,6 +158,7 @@ Mike Bland
 Martin Bless
 Pablo Bleyer
 Erik van Blokland
+Stéphane Blondon
 Eric Blossom
 Sergey Bobrov
 Finn Bock
diff --git a/Misc/NEWS.d/next/Library/2018-04-10-20-57-14.bpo-33256.ndHkqu.rst b/Misc/NEWS.d/next/Library/2018-04-10-20-57-14.bpo-33256.ndHkqu.rst
new file mode 100644
index 000000000000..a0605c04b4de
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2018-04-10-20-57-14.bpo-33256.ndHkqu.rst
@@ -0,0 +1 @@
+Fix display of ``<module>`` call in the html produced by ``cgitb.html()``. Patch by Stéphane Blondon.



More information about the Python-checkins mailing list