This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: cgi uses the locale encoding for log files
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.10
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: ethan.furman, methane, serhiy.storchaka, thatiparthy, vinay.sajip
Priority: normal Keywords: patch

Created on 2020-06-27 11:30 by serhiy.storchaka, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 25625 merged methane, 2021-04-26 08:51
Messages (7)
msg372462 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2020-06-27 11:30
The cgi module provides undocumented feasibility for logging. cgi.log() formats log message and appends it to the log file with name specified by cgi.logfile if it was not empty before the first use of cgi.log().

One of problems is that it uses the locale encoding for log file. Therefore the result depends on the locale at the moment of the first use of cgi.log().

We can fix this by using some fixed encoding (UTF-8). Or maybe just remove this undocumented feature.
msg372866 - (view) Author: Srinivas Reddy Thatiparthy(శ్రీనివాస్ రెడ్డి తాటిపర్తి) (thatiparthy) * Date: 2020-07-02 17:40
I am for keeping this functionality. Unless others in this nosy list think otherwise.
msg372867 - (view) Author: Ethan Furman (ethan.furman) * (Python committer) Date: 2020-07-02 17:46
Which functionality?

- cgi.log()

- opening with current locale

I don't mind keeping the function, but if the file isn't already opened I think using UTF-8 is an appropriate choice.
msg372870 - (view) Author: Srinivas Reddy Thatiparthy(శ్రీనివాస్ రెడ్డి తాటిపర్తి) (thatiparthy) * Date: 2020-07-02 18:11
My bad. I meant cgi.log(), I pressed submit changes in a hurry.

+1 for utf-8.
msg372872 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2020-07-02 18:49
Available options:

1. Do nothing (keep cgi.log() and continue to use the default encoding for open()).
2. Remove cgi.log(). I think that the deprecation period is not needed because the function is not documented, is not imported by star-import, and is not shown in help.
3. Make cgi.log() using UTF-8 for open(). This may break some existing code if cgi.log() is ever used.
4. Completely rewrite cgi.log() using the logging module.

In all options except 2 cgi.log() needs to be documented and advertised as a new feature. And we should ask ourself: do we need this feature? Does it have advantages over the logging package?

It was more visible in 2.0. But since adding __all__ in 2.1 (in e99d5ea25ba994491c773d9b5872332334ccd1c5) it is a hidden feature.
msg390154 - (view) Author: Inada Naoki (methane) * (Python committer) Date: 2021-04-03 23:44
+1 for removing.
But let's emit DeprecationWarning for now, and remove it later.
msg392276 - (view) Author: Inada Naoki (methane) * (Python committer) Date: 2021-04-29 02:36
New changeset e52ab42cedd2a5ef4c3c1a47d0cf96a8f06d051f by Inada Naoki in branch 'master':
bpo-41139: Deprecate `cgi.log()` (GH-25625)
Date User Action Args
2022-04-11 14:59:33adminsetgithub: 85311
2021-04-29 02:36:58methanesetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2021-04-29 02:36:12methanesetmessages: + msg392276
2021-04-26 08:51:03methanesetkeywords: + patch
stage: patch review
pull_requests: + pull_request24324
2021-04-03 23:44:32methanesetmessages: + msg390154
components: + Library (Lib)
versions: - Python 3.8, Python 3.9
2021-04-03 23:34:31methanesetnosy: + methane
2021-04-03 14:45:27serhiy.storchakalinkissue43711 superseder
2020-07-20 20:50:15Rhodri Jamessetnosy: - Rhodri James
2020-07-02 18:49:44serhiy.storchakasetmessages: + msg372872
2020-07-02 18:11:27thatiparthysetmessages: + msg372870
2020-07-02 17:46:13ethan.furmansetmessages: + msg372867
2020-07-02 17:40:49thatiparthysetnosy: + thatiparthy
messages: + msg372866
2020-06-27 11:32:06serhiy.storchakalinkissue41063 dependencies
2020-06-27 11:30:05serhiy.storchakacreate