]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-47061: deprecate cgi and cgitb (GH-32410)
authorBrett Cannon <brett@python.org>
Sat, 9 Apr 2022 00:15:35 +0000 (17:15 -0700)
committerGitHub <noreply@github.com>
Sat, 9 Apr 2022 00:15:35 +0000 (17:15 -0700)
Part of PEP 594.

Doc/whatsnew/3.11.rst
Lib/cgi.py
Lib/cgitb.py
Lib/distutils/config.py
Lib/test/test_cgi.py
Lib/test/test_cgitb.py
Lib/test/test_httpservers.py
Misc/NEWS.d/next/Library/2022-04-07-20-32-47.bpo-47061.TOufgh.rst [new file with mode: 0644]

index 2da01d8105ac6b805de59f3b296494253eef09c5..2758a268e957e56e6a3332070ad5e611076337d9 100644 (file)
@@ -834,6 +834,8 @@ Deprecated
 
   * :mod:`aifc`
   * :mod:`audioop`
+  * :mod:`cgi`
+  * :mod:`cgitb`
 
   (Contributed by Brett Cannon in :issue:`47061`.)
 
index 22897a14a9c12202575d809a23c21c8a3e7b7771..8787567be7c081c1012016302d4ec38644b0f0c3 100755 (executable)
@@ -53,6 +53,9 @@ __all__ = ["MiniFieldStorage", "FieldStorage", "parse", "parse_multipart",
            "print_form", "print_directory", "print_arguments",
            "print_environ_usage"]
 
+
+warnings._deprecated(__name__, remove=(3,13))
+
 # Logging support
 # ===============
 
index ec156843099d36376533bf33ddd5d49b9f8795ca..8ce0e833a989aa6a9f7f886763c26bd4dfe482f2 100644 (file)
@@ -31,8 +31,12 @@ import tempfile
 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
index 2171abd6969f6823454d704c5eea3e278bbe8005..a201c86a176844adaa0717f62d9db60772216ff4 100644 (file)
@@ -5,6 +5,7 @@ that uses .pypirc in the distutils.command package.
 """
 import os
 from configparser import RawConfigParser
+import warnings
 
 from distutils.cmd import Command
 
@@ -111,7 +112,9 @@ class PyPIRCCommand(Command):
 
     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)
index 06762f8872a302598ab63dc34280f5088abd2996..24486e4d95a7835de3b221e53783cd175f3ac1cf 100644 (file)
@@ -1,4 +1,3 @@
-import cgi
 import os
 import sys
 import tempfile
@@ -8,6 +7,9 @@ from io import StringIO, BytesIO
 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
index 590ffdea1122aca4086f41b2958c71f0160ae168..501c7fcce28e88e462b75bf86d6730eca41cd2a0 100644 (file)
@@ -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):
 
index d20b45e8e02f88a2f151ada78fd93212adb9db69..1f041aa121f974152d52c151a565bb8e3986438b 100644 (file)
@@ -570,14 +570,19 @@ print("Hello World")
 
 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 (file)
index 0000000..bd54249
--- /dev/null
@@ -0,0 +1 @@
+Deprecate cgi and cgitb.