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.

classification
Title: SystemExit incorrectly displays unicode message
Type: behavior Stage:
Components: Unicode Versions: Python 3.0, Python 2.7, Python 2.6
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: amaury.forgeotdarc, benjamin.peterson, ezio.melotti, georg.brandl, vstinner
Priority: normal Keywords: patch

Created on 2008-09-06 21:51 by amaury.forgeotdarc, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
handle_system_exit_unicode-trunk.patch vstinner, 2010-05-21 23:36
Messages (6)
msg72708 - (view) Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) Date: 2008-09-06 21:51
When SystemExit is raised with a string argument, it is printed as UTF-8
to the (libc) stderr, and does not use the terminal's encoding.

handle_system_exit() should use PyFile_WriteString() instead of
PyObject_Print().
msg88872 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2009-06-04 09:58
Ping?
msg89015 - (view) Author: Ezio Melotti (ezio.melotti) * (Python committer) Date: 2009-06-06 20:50
I did some more experiments, here are the results:

Windows XP, from cmd.exe (cp850):
Py 2.x:
>>> raise SystemExit(u'aeiou') # unicode string, ascii chars, works fine
aeiou

>>> raise SystemExit(u'àèìòù') # unicode string, non-ascii chars, no output


>>> raise SystemExit('àèìòù') # byte strings, non-ascii chars, works fine
àèìòù

Py 3.0:
>>> raise SystemExit('àèìòù') # unicode string, non-ascii chars, wrong
output
àèìòù

The output here is utf-8 and cmd shows it as cp850.


Linux, UTF-8 terminal:
Py 2.x:
>>> raise SystemExit(u'àèìòù') # unicode string, non-ascii chars, no output

There's no output even if the terminal uses utf-8.

Py 3.x:
>>> raise SystemExit('àèìòù') # unicode string, non-ascii chars, works fine
àèìòù


When a unicode string with non-ascii characters is passed:
* Py2 always fails (no output);
* Py3 works only when the terminal uses utf-8, otherwise it fails (the
chars are displayed using another encoding).
msg106271 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2010-05-21 23:36
Here is a patch for trunk. This bug is minor, and so I don't know if it can be commited to 2.7.

The patch adds also a test that I added to py3k in r81252:

"handle_system_exit() flushs files to warranty the output order

PyObject_Print() writes into the C object stderr, whereas PySys_WriteStderr() writes into the Python object sys.stderr. Each object has its own buffer, so call sys.stderr.flush() and fflush(stderr)."
msg106272 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2010-05-21 23:46
I applied a similar patch to py3k (r81457) to use sys.stderr encoding and error handler, instead of the default encoding (utf8).

Wait for the buildbot before backporting to 3.1.
msg106489 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2010-05-25 22:40
Commited to 2.7 (r81537) and 2.6 (r81539), blocked in 3.2 (r81538: py3k was already fixed by r81252).
History
Date User Action Args
2022-04-11 14:56:38adminsetgithub: 48048
2010-05-25 22:40:55vstinnersetstatus: open -> closed
resolution: fixed
messages: + msg106489
2010-05-21 23:46:54vstinnersetmessages: + msg106272
2010-05-21 23:36:32vstinnersetfiles: + handle_system_exit_unicode-trunk.patch

nosy: + vstinner, benjamin.peterson
messages: + msg106271

keywords: + patch
2009-06-06 20:50:02ezio.melottisetpriority: normal

type: behavior
components: + Unicode
versions: + Python 2.6, Python 2.7
nosy: + ezio.melotti

messages: + msg89015
2009-06-04 09:58:31georg.brandlsetnosy: + georg.brandl
messages: + msg88872
2008-09-06 21:51:01amaury.forgeotdarccreate