Skip to content

Commit 698865d

Browse files
authored
bpo-33843: Remove deprecated stuff in cgi module (GH-7662)
1 parent cb97073 commit 698865d

File tree

5 files changed

+7
-81
lines changed

5 files changed

+7
-81
lines changed

Doc/library/cgi.rst

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -284,18 +284,6 @@ algorithms implemented in this module in other circumstances.
284284
passed to :func:`urllib.parse.parse_qs` unchanged.
285285

286286

287-
.. function:: parse_qs(qs, keep_blank_values=False, strict_parsing=False)
288-
289-
This function is deprecated in this module. Use :func:`urllib.parse.parse_qs`
290-
instead. It is maintained here only for backward compatibility.
291-
292-
293-
.. function:: parse_qsl(qs, keep_blank_values=False, strict_parsing=False)
294-
295-
This function is deprecated in this module. Use :func:`urllib.parse.parse_qsl`
296-
instead. It is maintained here only for backward compatibility.
297-
298-
299287
.. function:: parse_multipart(fp, pdict, encoding="utf-8", errors="replace")
300288

301289
Parse input of type :mimetype:`multipart/form-data` (for file uploads).
@@ -348,20 +336,6 @@ algorithms implemented in this module in other circumstances.
348336
Print a list of useful (used by CGI) environment variables in HTML.
349337

350338

351-
.. function:: escape(s, quote=False)
352-
353-
Convert the characters ``'&'``, ``'<'`` and ``'>'`` in string *s* to HTML-safe
354-
sequences. Use this if you need to display text that might contain such
355-
characters in HTML. If the optional flag *quote* is true, the quotation mark
356-
character (``"``) is also translated; this helps for inclusion in an HTML
357-
attribute value delimited by double quotes, as in ``<a href="...">``. Note
358-
that single quotes are never translated.
359-
360-
.. deprecated:: 3.2
361-
This function is unsafe because *quote* is false by default, and therefore
362-
deprecated. Use :func:`html.escape` instead.
363-
364-
365339
.. _cgi-security:
366340

367341
Caring about security

Doc/whatsnew/3.8.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,10 @@ Removed
136136
to help eliminate confusion as to what Python interpreter the ``pyvenv``
137137
script is tied to. (Contributed by Brett Cannon in :issue:`25427`.)
138138

139+
* ``parse_qs``, ``parse_qsl``, and ``escape`` are removed from :mod:`cgi`
140+
module. They are deprecated from Python 3.2 or older.
141+
142+
139143

140144
Porting to Python 3.8
141145
=====================

Lib/cgi.py

Lines changed: 2 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,14 @@
3838
import urllib.parse
3939
from email.parser import FeedParser
4040
from email.message import Message
41-
from warnings import warn
4241
import html
4342
import locale
4443
import tempfile
4544

46-
__all__ = ["MiniFieldStorage", "FieldStorage",
47-
"parse", "parse_qs", "parse_qsl", "parse_multipart",
45+
__all__ = ["MiniFieldStorage", "FieldStorage", "parse", "parse_multipart",
4846
"parse_header", "test", "print_exception", "print_environ",
4947
"print_form", "print_directory", "print_arguments",
50-
"print_environ_usage", "escape"]
48+
"print_environ_usage"]
5149

5250
# Logging support
5351
# ===============
@@ -183,21 +181,6 @@ def parse(fp=None, environ=os.environ, keep_blank_values=0, strict_parsing=0):
183181
encoding=encoding)
184182

185183

186-
# parse query string function called from urlparse,
187-
# this is done in order to maintain backward compatibility.
188-
189-
def parse_qs(qs, keep_blank_values=0, strict_parsing=0):
190-
"""Parse a query given as a string argument."""
191-
warn("cgi.parse_qs is deprecated, use urllib.parse.parse_qs instead",
192-
DeprecationWarning, 2)
193-
return urllib.parse.parse_qs(qs, keep_blank_values, strict_parsing)
194-
195-
def parse_qsl(qs, keep_blank_values=0, strict_parsing=0):
196-
"""Parse a query given as a string argument."""
197-
warn("cgi.parse_qsl is deprecated, use urllib.parse.parse_qsl instead",
198-
DeprecationWarning, 2)
199-
return urllib.parse.parse_qsl(qs, keep_blank_values, strict_parsing)
200-
201184
def parse_multipart(fp, pdict, encoding="utf-8", errors="replace"):
202185
"""Parse multipart input.
203186
@@ -974,18 +957,6 @@ def print_environ_usage():
974957
# Utilities
975958
# =========
976959

977-
def escape(s, quote=None):
978-
"""Deprecated API."""
979-
warn("cgi.escape is deprecated, use html.escape instead",
980-
DeprecationWarning, stacklevel=2)
981-
s = s.replace("&", "&amp;") # Must be done first!
982-
s = s.replace("<", "&lt;")
983-
s = s.replace(">", "&gt;")
984-
if quote:
985-
s = s.replace('"', "&quot;")
986-
return s
987-
988-
989960
def valid_boundary(s):
990961
import re
991962
if isinstance(s, bytes):

Lib/test/test_cgi.py

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import sys
55
import tempfile
66
import unittest
7-
import warnings
87
from collections import namedtuple
98
from io import StringIO, BytesIO
109
from test import support
@@ -163,15 +162,6 @@ def test_fieldstorage_invalid(self):
163162
fs = cgi.FieldStorage(headers={'content-type':'text/plain'})
164163
self.assertRaises(TypeError, bool, fs)
165164

166-
def test_escape(self):
167-
# cgi.escape() is deprecated.
168-
with warnings.catch_warnings():
169-
warnings.filterwarnings('ignore', r'cgi\.escape',
170-
DeprecationWarning)
171-
self.assertEqual("test &amp; string", cgi.escape("test & string"))
172-
self.assertEqual("&lt;test string&gt;", cgi.escape("<test string>"))
173-
self.assertEqual("&quot;test string&quot;", cgi.escape('"test string"', True))
174-
175165
def test_strict(self):
176166
for orig, expect in parse_strict_test_cases:
177167
# Test basic parsing
@@ -449,20 +439,6 @@ def testQSAndFormDataFile(self):
449439
v = gen_result(data, environ)
450440
self.assertEqual(result, v)
451441

452-
def test_deprecated_parse_qs(self):
453-
# this func is moved to urllib.parse, this is just a sanity check
454-
with check_warnings(('cgi.parse_qs is deprecated, use urllib.parse.'
455-
'parse_qs instead', DeprecationWarning)):
456-
self.assertEqual({'a': ['A1'], 'B': ['B3'], 'b': ['B2']},
457-
cgi.parse_qs('a=A1&b=B2&B=B3'))
458-
459-
def test_deprecated_parse_qsl(self):
460-
# this func is moved to urllib.parse, this is just a sanity check
461-
with check_warnings(('cgi.parse_qsl is deprecated, use urllib.parse.'
462-
'parse_qsl instead', DeprecationWarning)):
463-
self.assertEqual([('a', 'A1'), ('b', 'B2'), ('B', 'B3')],
464-
cgi.parse_qsl('a=A1&b=B2&B=B3'))
465-
466442
def test_parse_header(self):
467443
self.assertEqual(
468444
cgi.parse_header("text/plain"),
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Remove deprecated ``cgi.escape``, ``cgi.parse_qs`` and ``cgi.parse_qsl``.

0 commit comments

Comments
 (0)