[Python-checkins] bpo-44647: Fix test_httpservers failing on Unicode characters in os.environ on Windows (GH-27161) (#27169)
ambv
webhook-mailer at python.org
Thu Jul 15 16:09:36 EDT 2021
https://github.com/python/cpython/commit/356bdff1e952f2ab7fdebae855bd78b401b735c4
commit: 356bdff1e952f2ab7fdebae855bd78b401b735c4
branch: 3.10
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: ambv <lukasz at langa.pl>
date: 2021-07-15T22:09:26+02:00
summary:
bpo-44647: Fix test_httpservers failing on Unicode characters in os.environ on Windows (GH-27161) (#27169)
GH-23638 introduced a new test for Accept: headers in CGI HTTP servers. This test serializes all of os.environ on the server side. For non-UTF8 locales this can fail for some Unicode characters found in environment variables. This change fixes the HTTP_ACCEPT test.
(cherry picked from commit 82b218f36ce6ef910bda5af227a9fd5be613c94f)
Co-authored-by: Łukasz Langa <lukasz at langa.pl>
files:
M Lib/test/test_httpservers.py
diff --git a/Lib/test/test_httpservers.py b/Lib/test/test_httpservers.py
index aeea020d2416d..69790ec746314 100644
--- a/Lib/test/test_httpservers.py
+++ b/Lib/test/test_httpservers.py
@@ -593,9 +593,18 @@ def test_html_escape_filename(self):
#!%s
import os
-print("Content-type: text/plain")
+print("X-ambv: was here")
+print("Content-type: text/html")
print()
-print(repr(os.environ))
+print("<pre>")
+for k, v in os.environ.items():
+ try:
+ k.encode('ascii')
+ v.encode('ascii')
+ except UnicodeEncodeError:
+ continue # see: BPO-44647
+ print(f"{k}={v}")
+print("</pre>")
"""
@@ -850,8 +859,8 @@ def test_accept(self):
with self.subTest(headers):
res = self.request('/cgi-bin/file6.py', 'GET', headers=headers)
self.assertEqual(http.HTTPStatus.OK, res.status)
- expected = f"'HTTP_ACCEPT': {expected!r}"
- self.assertIn(expected.encode('ascii'), res.read())
+ expected = f"HTTP_ACCEPT={expected}".encode('ascii')
+ self.assertIn(expected, res.read())
class SocketlessRequestHandler(SimpleHTTPRequestHandler):
More information about the Python-checkins
mailing list