diff --git a/Doc/whatsnew/3.12.rst b/Doc/whatsnew/3.12.rst index 45a5e5062d55b6..319d30c807c19a 100644 --- a/Doc/whatsnew/3.12.rst +++ b/Doc/whatsnew/3.12.rst @@ -700,6 +700,9 @@ Removed *context* parameter instead. (Contributed by Victor Stinner in :gh:`94172`.) +* :mod:`cgi`: Remove ``cgi.log()``, deprecated since Python 3.10. + Use :mod:`logging` instead. + (Contributed by Hugo van Kemenade in :gh:`101850`.) Porting to Python 3.12 ====================== diff --git a/Lib/cgi.py b/Lib/cgi.py index 8787567be7c081..cb737583f2792a 100755 --- a/Lib/cgi.py +++ b/Lib/cgi.py @@ -56,68 +56,6 @@ warnings._deprecated(__name__, remove=(3,13)) -# Logging support -# =============== - -logfile = "" # Filename to log to, if not empty -logfp = None # File object to log to, if not None - -def initlog(*allargs): - """Write a log message, if there is a log file. - - Even though this function is called initlog(), you should always - use log(); log is a variable that is set either to initlog - (initially), to dolog (once the log file has been opened), or to - nolog (when logging is disabled). - - The first argument is a format string; the remaining arguments (if - any) are arguments to the % operator, so e.g. - log("%s: %s", "a", "b") - will write "a: b" to the log file, followed by a newline. - - If the global logfp is not None, it should be a file object to - which log data is written. - - If the global logfp is None, the global logfile may be a string - giving a filename to open, in append mode. This file should be - world writable!!! If the file can't be opened, logging is - silently disabled (since there is no safe place where we could - send an error message). - - """ - global log, logfile, logfp - warnings.warn("cgi.log() is deprecated as of 3.10. Use logging instead", - DeprecationWarning, stacklevel=2) - if logfile and not logfp: - try: - logfp = open(logfile, "a", encoding="locale") - except OSError: - pass - if not logfp: - log = nolog - else: - log = dolog - log(*allargs) - -def dolog(fmt, *args): - """Write a log message to the log file. See initlog() for docs.""" - logfp.write(fmt%args + "\n") - -def nolog(*allargs): - """Dummy function, assigned to log when logging is disabled.""" - pass - -def closelog(): - """Close the log file.""" - global log, logfile, logfp - logfile = '' - if logfp: - logfp.close() - logfp = None - log = initlog - -log = initlog # The current logging function - # Parsing functions # ================= diff --git a/Lib/test/test_cgi.py b/Lib/test/test_cgi.py index 24486e4d95a783..d288b279be2004 100644 --- a/Lib/test/test_cgi.py +++ b/Lib/test/test_cgi.py @@ -223,20 +223,6 @@ def test_separator(self): else: self.assertEqual(fs.getvalue(key), expect_val[0]) - @warnings_helper.ignore_warnings(category=DeprecationWarning) - def test_log(self): - cgi.log("Testing") - - cgi.logfp = StringIO() - cgi.initlog("%s", "Testing initlog 1") - cgi.log("%s", "Testing log 2") - self.assertEqual(cgi.logfp.getvalue(), "Testing initlog 1\nTesting log 2\n") - if os.path.exists(os.devnull): - cgi.logfp = None - cgi.logfile = os.devnull - cgi.initlog("%s", "Testing log 3") - self.addCleanup(cgi.closelog) - cgi.log("Testing log 4") def test_fieldstorage_readline(self): # FieldStorage uses readline, which has the capacity to read all diff --git a/Lib/test/test_pyclbr.py b/Lib/test/test_pyclbr.py index 23453e340159db..195c5327275c85 100644 --- a/Lib/test/test_pyclbr.py +++ b/Lib/test/test_pyclbr.py @@ -221,7 +221,7 @@ def test_others(self): cm('random', ignore=('Random',)) # from _random import Random as CoreGenerator with warnings.catch_warnings(): warnings.simplefilter('ignore', DeprecationWarning) - cm('cgi', ignore=('log',)) # set with = in module + cm('cgi') # set with = in module cm('pickle', ignore=('partial', 'PickleBuffer')) with warnings.catch_warnings(): warnings.simplefilter('ignore', DeprecationWarning) diff --git a/Misc/NEWS.d/next/Library/2023-02-12-19-10-42.gh-issue-101850.I62r55.rst b/Misc/NEWS.d/next/Library/2023-02-12-19-10-42.gh-issue-101850.I62r55.rst new file mode 100644 index 00000000000000..f36bf77209551d --- /dev/null +++ b/Misc/NEWS.d/next/Library/2023-02-12-19-10-42.gh-issue-101850.I62r55.rst @@ -0,0 +1,2 @@ +:mod:`cgi`: Remove ``cgi.log()``, deprecated since Python 3.10. Use +:mod:`logging` instead. Patch by Hugo van Kemenade.