|
| 1 | +:mod:`!cgi` --- Common Gateway Interface support |
| 2 | +================================================ |
| 3 | + |
| 4 | +.. module:: cgi |
| 5 | + :synopsis: Removed in 3.13. |
| 6 | + :deprecated: |
| 7 | + |
| 8 | +This module is no longer part of the Python standard library. |
| 9 | +It was :ref:`removed in Python 3.13 <whatsnew313-pep594>` after |
| 10 | +being deprecated in Python 3.11. The removal was decided in :pep:`594`. |
| 11 | + |
| 12 | +A fork of the module on PyPI can be used instead: :pypi:`legacy-cgi`. |
| 13 | + |
| 14 | +If you want to update your code using supported standard library modules: |
| 15 | + |
| 16 | +* ``cgi.FieldStorage`` can typically be replaced with |
| 17 | + :func:`urllib.parse.parse_qsl` for ``GET`` and ``HEAD`` requests, and the |
| 18 | + :mod:`email.message` module or :pypi:`multipart` PyPI project for ``POST`` |
| 19 | + and ``PUT``. |
| 20 | + |
| 21 | +* ``cgi.parse()`` can be replaced by calling :func:`urllib.parse.parse_qs` |
| 22 | + directly on the desired query string, except for ``multipart/form-data`` |
| 23 | + input, which can be handled as described for ``cgi.parse_multipart()``. |
| 24 | + |
| 25 | +* ``cgi.parse_multipart()`` can be replaced with the functionality in the |
| 26 | + :mod:`email` package (e.g. :class:`email.message.EmailMessage` and |
| 27 | + :class:`email.message.Message`) which implements the same MIME RFCs, or |
| 28 | + with the :pypi:`multipart` PyPI project. |
| 29 | + |
| 30 | +* ``cgi.parse_header()`` can be replaced with the functionality in the |
| 31 | + :mod:`email` package, which implements the same MIME RFCs. For example, |
| 32 | + with :class:`email.message.EmailMessage`:: |
| 33 | + |
| 34 | + from email.message import EmailMessage |
| 35 | + msg = EmailMessage() |
| 36 | + msg['content-type'] = 'application/json; charset="utf8"' |
| 37 | + main, params = msg.get_content_type(), msg['content-type'].params |
0 commit comments