Skip to content

Commit e52ab42

Browse files
authored
bpo-41139: Deprecate cgi.log() (GH-25625)
1 parent a692565 commit e52ab42

File tree

4 files changed

+10
-1
lines changed

4 files changed

+10
-1
lines changed

Doc/whatsnew/3.10.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1427,6 +1427,9 @@ Deprecated
14271427
Python 3.12. Use :meth:`pathlib.Path.hardlink_to` instead.
14281428
(Contributed by Barney Gale in :issue:`39950`.)
14291429
1430+
* ``cgi.log()`` is deprecated and slated for for removal in Python 3.12.
1431+
(Contributed by Inada Naoki in :issue:`41139`.)
1432+
14301433
14311434
Removed
14321435
=======

Lib/cgi.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
import html
4242
import locale
4343
import tempfile
44+
import warnings
4445

4546
__all__ = ["MiniFieldStorage", "FieldStorage", "parse", "parse_multipart",
4647
"parse_header", "test", "print_exception", "print_environ",
@@ -77,9 +78,11 @@ def initlog(*allargs):
7778
7879
"""
7980
global log, logfile, logfp
81+
warnings.warn("cgi.log() is deprecated as of 3.10. Use logging instead",
82+
DeprecationWarning, stacklevel=2)
8083
if logfile and not logfp:
8184
try:
82-
logfp = open(logfile, "a")
85+
logfp = open(logfile, "a", encoding="locale")
8386
except OSError:
8487
pass
8588
if not logfp:

Lib/test/test_cgi.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from collections import namedtuple
77
from io import StringIO, BytesIO
88
from test import support
9+
from test.support import warnings_helper
910

1011
class HackedSysModule:
1112
# The regression test will have real values in sys.argv, which
@@ -220,6 +221,7 @@ def test_separator(self):
220221
else:
221222
self.assertEqual(fs.getvalue(key), expect_val[0])
222223

224+
@warnings_helper.ignore_warnings(category=DeprecationWarning)
223225
def test_log(self):
224226
cgi.log("Testing")
225227

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Deprecate undocumented ``cgi.log()`` API.

0 commit comments

Comments
 (0)