Skip to content

Commit 71354ad

Browse files
authored
gh-92611: Add details on replacements for cgi utility funcs (GH-92792)
Per @brettcannon 's [suggestions on the Discourse thread](https://discuss.python.org/t/pep-594-take-2-removing-dead-batteries-from-the-standard-library/13508/51), discussed in #92611 and as a followup to PR #92612 , this PR add additional specific per-function replacement information for the utility functions in the `cgi` module deprecated by PEP 594 (PEP-594). @brettcannon , should this be backported (without the `deprecated-removed` , which I would update it accordingly and re-add in my other PR adding that to the others for 3.11+), or just go in 3.11+?
1 parent 96464e5 commit 71354ad

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

Doc/library/cgi.rst

+31
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@
1919
The :mod:`cgi` module is deprecated
2020
(see :pep:`PEP 594 <594#cgi>` for details and alternatives).
2121

22+
The :class:`FieldStorage` class can typically be replaced with
23+
:func:`urllib.parse.parse_qsl` for ``GET`` and ``HEAD`` requests,
24+
and the :mod:`email.message` module or
25+
`multipart <https://pypi.org/project/multipart/>`_ for ``POST`` and ``PUT``.
26+
Most :ref:`utility functions <functions-in-cgi-module>` have replacements.
27+
2228
--------------
2329

2430
Support module for Common Gateway Interface (CGI) scripts.
@@ -293,6 +299,12 @@ algorithms implemented in this module in other circumstances.
293299
``sys.stdin``). The *keep_blank_values*, *strict_parsing* and *separator* parameters are
294300
passed to :func:`urllib.parse.parse_qs` unchanged.
295301

302+
.. deprecated-removed:: 3.11 3.13
303+
This function, like the rest of the :mod:`cgi` module, is deprecated.
304+
It can be replaced by calling :func:`urllib.parse.parse_qs` directly
305+
on the desired query string (except for ``multipart/form-data`` input,
306+
which can be handled as described for :func:`parse_multipart`).
307+
296308

297309
.. function:: parse_multipart(fp, pdict, encoding="utf-8", errors="replace", separator="&")
298310

@@ -316,12 +328,31 @@ algorithms implemented in this module in other circumstances.
316328
.. versionchanged:: 3.10
317329
Added the *separator* parameter.
318330

331+
.. deprecated-removed:: 3.11 3.13
332+
This function, like the rest of the :mod:`cgi` module, is deprecated.
333+
It can be replaced with the functionality in the :mod:`email` package
334+
(e.g. :class:`email.message.EmailMessage`/:class:`email.message.Message`)
335+
which implements the same MIME RFCs, or with the
336+
`multipart <https://pypi.org/project/multipart/>`__ PyPI project.
337+
319338

320339
.. function:: parse_header(string)
321340

322341
Parse a MIME header (such as :mailheader:`Content-Type`) into a main value and a
323342
dictionary of parameters.
324343

344+
.. deprecated-removed:: 3.11 3.13
345+
This function, like the rest of the :mod:`cgi` module, is deprecated.
346+
It can be replaced with the functionality in the :mod:`email` package,
347+
which implements the same MIME RFCs.
348+
349+
For example, with :class:`email.message.EmailMessage`::
350+
351+
from email.message import EmailMessage
352+
msg = EmailMessage()
353+
msg['content-type'] = 'application/json; charset="utf8"'
354+
main, params = msg.get_content_type(), msg['content-type'].params
355+
325356

326357
.. function:: test()
327358

0 commit comments

Comments
 (0)