Skip to content

Commit cd29bd1

Browse files
authored
bpo-47061: deprecate cgi and cgitb (GH-32410)
Part of PEP 594.
1 parent 1c8b3b5 commit cd29bd1

File tree

8 files changed

+28
-7
lines changed

8 files changed

+28
-7
lines changed

Doc/whatsnew/3.11.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -834,6 +834,8 @@ Deprecated
834834

835835
* :mod:`aifc`
836836
* :mod:`audioop`
837+
* :mod:`cgi`
838+
* :mod:`cgitb`
837839

838840
(Contributed by Brett Cannon in :issue:`47061`.)
839841

Lib/cgi.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@
5353
"print_form", "print_directory", "print_arguments",
5454
"print_environ_usage"]
5555

56+
57+
warnings._deprecated(__name__, remove=(3,13))
58+
5659
# Logging support
5760
# ===============
5861

Lib/cgitb.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,12 @@
3131
import time
3232
import tokenize
3333
import traceback
34+
import warnings
3435
from html import escape as html_escape
3536

37+
warnings._deprecated(__name__, remove=(3, 13))
38+
39+
3640
def reset():
3741
"""Return a string that resets the CGI and browser to a known state."""
3842
return '''<!--: spam

Lib/distutils/config.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"""
66
import os
77
from configparser import RawConfigParser
8+
import warnings
89

910
from distutils.cmd import Command
1011

@@ -111,7 +112,9 @@ def _read_pypirc(self):
111112

112113
def _read_pypi_response(self, response):
113114
"""Read and decode a PyPI HTTP response."""
114-
import cgi
115+
with warnings.catch_warnings():
116+
warnings.simplefilter("ignore", DeprecationWarning)
117+
import cgi
115118
content_type = response.getheader('content-type', 'text/plain')
116119
encoding = cgi.parse_header(content_type)[1].get('charset', 'ascii')
117120
return response.read().decode(encoding)

Lib/test/test_cgi.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import cgi
21
import os
32
import sys
43
import tempfile
@@ -8,6 +7,9 @@
87
from test import support
98
from test.support import warnings_helper
109

10+
cgi = warnings_helper.import_deprecated("cgi")
11+
12+
1113
class HackedSysModule:
1214
# The regression test will have real values in sys.argv, which
1315
# will completely confuse the test of the cgi module

Lib/test/test_cgitb.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
from test.support.os_helper import temp_dir
22
from test.support.script_helper import assert_python_failure
3+
from test.support.warnings_helper import import_deprecated
34
import unittest
45
import sys
5-
import cgitb
6+
cgitb = import_deprecated("cgitb")
67

78
class TestCgitb(unittest.TestCase):
89

Lib/test/test_httpservers.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -570,14 +570,19 @@ def test_html_escape_filename(self):
570570

571571
cgi_file2 = """\
572572
#!%s
573-
import cgi
573+
import os
574+
import sys
575+
import urllib.parse
574576
575577
print("Content-type: text/html")
576578
print()
577579
578-
form = cgi.FieldStorage()
579-
print("%%s, %%s, %%s" %% (form.getfirst("spam"), form.getfirst("eggs"),
580-
form.getfirst("bacon")))
580+
content_length = int(os.environ["CONTENT_LENGTH"])
581+
query_string = sys.stdin.buffer.read(content_length)
582+
params = {key.decode("utf-8"): val.decode("utf-8")
583+
for key, val in urllib.parse.parse_qsl(query_string)}
584+
585+
print("%%s, %%s, %%s" %% (params["spam"], params["eggs"], params["bacon"]))
581586
"""
582587

583588
cgi_file4 = """\
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Deprecate cgi and cgitb.

0 commit comments

Comments
 (0)