Skip to content

Commit 272f2e6

Browse files
committed
Fix cgi tests to be compatible with behaviour of older Python versions
1 parent 4a89826 commit 272f2e6

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

tools/wptserve/wptserve/cgi/cgi.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,10 @@ def initlog(*allargs):
8989
DeprecationWarning, stacklevel=2)
9090
if logfile and not logfp:
9191
try:
92-
logfp = open(logfile, "a", encoding="locale")
92+
kwargs = {}
93+
if sys.version_info > (3, 9):
94+
kwargs["encoding"] = "locale"
95+
logfp = open(logfile, "a", **kwargs)
9396
except OSError:
9497
pass
9598
if not logfp:

tools/wptserve/wptserve/cgi/test_cgi.py

+5
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ class HackedSysModule:
7474
# will completely confuse the test of the cgi module
7575
argv = []
7676
stdin = sys.stdin
77+
version_info = sys.version_info
7778

7879
cgi.sys = HackedSysModule()
7980

@@ -153,6 +154,10 @@ def do_test(buf, method):
153154
})
154155
]
155156

157+
# The behaviour of urllib.parse.parse_qs with empty input changed in Python 3.11
158+
if sys.version_info < (3, 11):
159+
parse_strict_test_cases[0] = ("", ValueError("bad query field: ''"))
160+
156161
def norm(seq):
157162
return sorted(seq, key=repr)
158163

0 commit comments

Comments
 (0)