[Python-checkins] bpo-47061: deprecate cgi and cgitb (GH-32410)
brettcannon
webhook-mailer at python.org
Fri Apr 8 20:15:46 EDT 2022
https://github.com/python/cpython/commit/cd29bd13ef1fe18970c5d43b66c545dd03117cb9
commit: cd29bd13ef1fe18970c5d43b66c545dd03117cb9
branch: main
author: Brett Cannon <brett at python.org>
committer: brettcannon <brett at python.org>
date: 2022-04-08T17:15:35-07:00
summary:
bpo-47061: deprecate cgi and cgitb (GH-32410)
Part of PEP 594.
files:
A Misc/NEWS.d/next/Library/2022-04-07-20-32-47.bpo-47061.TOufgh.rst
M Doc/whatsnew/3.11.rst
M Lib/cgi.py
M Lib/cgitb.py
M Lib/distutils/config.py
M Lib/test/test_cgi.py
M Lib/test/test_cgitb.py
M Lib/test/test_httpservers.py
diff --git a/Doc/whatsnew/3.11.rst b/Doc/whatsnew/3.11.rst
index 2da01d8105ac6..2758a268e957e 100644
--- a/Doc/whatsnew/3.11.rst
+++ b/Doc/whatsnew/3.11.rst
@@ -834,6 +834,8 @@ Deprecated
* :mod:`aifc`
* :mod:`audioop`
+ * :mod:`cgi`
+ * :mod:`cgitb`
(Contributed by Brett Cannon in :issue:`47061`.)
diff --git a/Lib/cgi.py b/Lib/cgi.py
index 22897a14a9c12..8787567be7c08 100755
--- a/Lib/cgi.py
+++ b/Lib/cgi.py
@@ -53,6 +53,9 @@
"print_form", "print_directory", "print_arguments",
"print_environ_usage"]
+
+warnings._deprecated(__name__, remove=(3,13))
+
# Logging support
# ===============
diff --git a/Lib/cgitb.py b/Lib/cgitb.py
index ec156843099d3..8ce0e833a989a 100644
--- a/Lib/cgitb.py
+++ b/Lib/cgitb.py
@@ -31,8 +31,12 @@
import time
import tokenize
import traceback
+import warnings
from html import escape as html_escape
+warnings._deprecated(__name__, remove=(3, 13))
+
+
def reset():
"""Return a string that resets the CGI and browser to a known state."""
return '''<!--: spam
diff --git a/Lib/distutils/config.py b/Lib/distutils/config.py
index 2171abd6969f6..a201c86a17684 100644
--- a/Lib/distutils/config.py
+++ b/Lib/distutils/config.py
@@ -5,6 +5,7 @@
"""
import os
from configparser import RawConfigParser
+import warnings
from distutils.cmd import Command
@@ -111,7 +112,9 @@ def _read_pypirc(self):
def _read_pypi_response(self, response):
"""Read and decode a PyPI HTTP response."""
- import cgi
+ with warnings.catch_warnings():
+ warnings.simplefilter("ignore", DeprecationWarning)
+ import cgi
content_type = response.getheader('content-type', 'text/plain')
encoding = cgi.parse_header(content_type)[1].get('charset', 'ascii')
return response.read().decode(encoding)
diff --git a/Lib/test/test_cgi.py b/Lib/test/test_cgi.py
index 06762f8872a30..24486e4d95a78 100644
--- a/Lib/test/test_cgi.py
+++ b/Lib/test/test_cgi.py
@@ -1,4 +1,3 @@
-import cgi
import os
import sys
import tempfile
@@ -8,6 +7,9 @@
from test import support
from test.support import warnings_helper
+cgi = warnings_helper.import_deprecated("cgi")
+
+
class HackedSysModule:
# The regression test will have real values in sys.argv, which
# will completely confuse the test of the cgi module
diff --git a/Lib/test/test_cgitb.py b/Lib/test/test_cgitb.py
index 590ffdea1122a..501c7fcce28e8 100644
--- a/Lib/test/test_cgitb.py
+++ b/Lib/test/test_cgitb.py
@@ -1,8 +1,9 @@
from test.support.os_helper import temp_dir
from test.support.script_helper import assert_python_failure
+from test.support.warnings_helper import import_deprecated
import unittest
import sys
-import cgitb
+cgitb = import_deprecated("cgitb")
class TestCgitb(unittest.TestCase):
diff --git a/Lib/test/test_httpservers.py b/Lib/test/test_httpservers.py
index d20b45e8e02f8..1f041aa121f97 100644
--- a/Lib/test/test_httpservers.py
+++ b/Lib/test/test_httpservers.py
@@ -570,14 +570,19 @@ def test_html_escape_filename(self):
cgi_file2 = """\
#!%s
-import cgi
+import os
+import sys
+import urllib.parse
print("Content-type: text/html")
print()
-form = cgi.FieldStorage()
-print("%%s, %%s, %%s" %% (form.getfirst("spam"), form.getfirst("eggs"),
- form.getfirst("bacon")))
+content_length = int(os.environ["CONTENT_LENGTH"])
+query_string = sys.stdin.buffer.read(content_length)
+params = {key.decode("utf-8"): val.decode("utf-8")
+ for key, val in urllib.parse.parse_qsl(query_string)}
+
+print("%%s, %%s, %%s" %% (params["spam"], params["eggs"], params["bacon"]))
"""
cgi_file4 = """\
diff --git a/Misc/NEWS.d/next/Library/2022-04-07-20-32-47.bpo-47061.TOufgh.rst b/Misc/NEWS.d/next/Library/2022-04-07-20-32-47.bpo-47061.TOufgh.rst
new file mode 100644
index 0000000000000..bd5424979c2ac
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2022-04-07-20-32-47.bpo-47061.TOufgh.rst
@@ -0,0 +1 @@
+Deprecate cgi and cgitb.
More information about the Python-checkins
mailing list