classification
Title: cgi uses the locale encoding for log files
Type: behavior Stage:
Components: Versions: Python 3.10, Python 3.9, Python 3.8
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: Rhodri James, ethan.furman, serhiy.storchaka, thatiparthy, vinay.sajip
Priority: normal Keywords:

Created on 2020-06-27 11:30 by serhiy.storchaka, last changed 2020-07-02 18:49 by serhiy.storchaka.

Messages (5)
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.
History
Date User Action Args
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