Issue 3798: SystemExit incorrectly displays unicode message (original) (raw)
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).
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)."