[Python-checkins] bpo-35565: Add detail to assertion failure message in wsgiref (GH-11293)

Raymond Hettinger webhook-mailer at python.org
Tue Dec 25 18:19:16 EST 2018


https://github.com/python/cpython/commit/5ef4fc241aea6759ef3f55b1ef564aebc492a0db
commit: 5ef4fc241aea6759ef3f55b1ef564aebc492a0db
branch: master
author: Cheryl Sabella <cheryl.sabella at gmail.com>
committer: Raymond Hettinger <rhettinger at users.noreply.github.com>
date: 2018-12-25T15:19:11-08:00
summary:

bpo-35565: Add detail to assertion failure message in wsgiref (GH-11293)

files:
M Lib/test/test_wsgiref.py
M Lib/wsgiref/handlers.py

diff --git a/Lib/test/test_wsgiref.py b/Lib/test/test_wsgiref.py
index 737dfed3a51e..3a953d841b88 100644
--- a/Lib/test/test_wsgiref.py
+++ b/Lib/test/test_wsgiref.py
@@ -193,6 +193,19 @@ def bad_app(environ, start_response):
                 ))
                 self.assertEqual(err.splitlines()[-2], exc_message)
 
+    @unittest.skipIf(support.python_is_optimized(),
+                     "Python was compiled with optimizations")
+    def test_hop_by_hop_validation_error(self):
+        def bad_app(environ, start_response):
+            start_response("200 OK", [('Content-Type', 'text/plain'),
+                                      ('Connection', 'close')])
+            return ["Hello, world!"]
+        out, err = run_amock(bad_app)
+        self.assertTrue(out.endswith(
+            b"A server error occurred.  Please contact the administrator."
+        ))
+        self.assertRaises(AssertionError)
+
     def test_wsgi_input(self):
         def bad_app(e,s):
             e["wsgi.input"].read()
diff --git a/Lib/wsgiref/handlers.py b/Lib/wsgiref/handlers.py
index f4300b831a44..28ed9b7a6d03 100644
--- a/Lib/wsgiref/handlers.py
+++ b/Lib/wsgiref/handlers.py
@@ -233,7 +233,8 @@ def start_response(self, status, headers,exc_info=None):
             for name, val in headers:
                 name = self._convert_string_type(name, "Header name")
                 val = self._convert_string_type(val, "Header value")
-                assert not is_hop_by_hop(name),"Hop-by-hop headers not allowed"
+                assert not is_hop_by_hop(name),\
+                       f"Hop-by-hop header, '{name}: {val}', not allowed"
 
         return self.write
 



More information about the Python-checkins mailing list