Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bpo-47061: deprecate cgi and cgitb #32410

Merged
merged 1 commit into from
Apr 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Doc/whatsnew/3.11.rst
Original file line number Diff line number Diff line change
Expand Up @@ -834,6 +834,8 @@ Deprecated

* :mod:`aifc`
* :mod:`audioop`
* :mod:`cgi`
* :mod:`cgitb`

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

Expand Down
3 changes: 3 additions & 0 deletions Lib/cgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@
"print_form", "print_directory", "print_arguments",
"print_environ_usage"]


warnings._deprecated(__name__, remove=(3,13))

# Logging support
# ===============

Expand Down
4 changes: 4 additions & 0 deletions Lib/cgitb.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion Lib/distutils/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"""
import os
from configparser import RawConfigParser
import warnings

from distutils.cmd import Command

Expand Down Expand Up @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion Lib/test/test_cgi.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import cgi
import os
import sys
import tempfile
Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion Lib/test/test_cgitb.py
Original file line number Diff line number Diff line change
@@ -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):

Expand Down
13 changes: 9 additions & 4 deletions Lib/test/test_httpservers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = """\
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Deprecate cgi and cgitb.