[ python-Bugs-1421664 ] [win32] stderr atty encoding not set
SourceForge.net
noreply at sourceforge.net
Mon Apr 3 12:57:36 CEST 2006
Bugs item #1421664, was opened at 2006-02-01 18:25
Message generated for change (Comment added) made by loewis
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1421664&group_id=5470
Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Python Library
Group: Python 2.4
>Status: Closed
>Resolution: Fixed
Priority: 6
Submitted By: Snaury (snaury)
Assigned to: Martin v. Löwis (loewis)
Summary: [win32] stderr atty encoding not set
Initial Comment:
When starting python console application under windows,
output of unicode strings to console fails because of
ansi encoding. I found that in file
Python-2.4.2/Python/sysmodule, _PySys_Init functions,
setting encoding on stderr was forgotten:
#ifdef MS_WINDOWS
if(isatty(_fileno(stdin))){
sprintf(buf, "cp%d", GetConsoleCP());
if (!PyFile_SetEncoding(sysin, buf))
return NULL;
}
if(isatty(_fileno(stdout))) {
sprintf(buf, "cp%d", GetConsoleOutputCP());
if (!PyFile_SetEncoding(sysout, buf))
return NULL;
}
#endif
I think the following lines should be added:
if(isatty(_fileno(stderr))) {
sprintf(buf, "cp%d", GetConsoleOutputCP());
if (!PyFile_SetEncoding(syserr, buf))
return NULL;
}
Otherwise it's inconsistant, as if we set it to sysout,
why not on syserr? And, for example, this code will not
work properly:
#!/usr/bin/env python
# -*- encoding: mbcs -*-
import sys
reload(sys) # bring setdefaultencoding back!
sys.setdefaultencoding("mbcs")
sys.stderr.write(u"<native text>\n")
Instead of native text garbage will be printed (if you
change it to sys.stdout, proper text displayed), and
there is no way I know to properly determine and set
encoding just for stderr (file.encoding is read-only,
after all).
----------------------------------------------------------------------
>Comment By: Martin v. Löwis (loewis)
Date: 2006-04-03 12:57
Message:
Logged In: YES
user_id=21627
Thanks for the report. This is now fixed in #43581.
----------------------------------------------------------------------
Comment By: Snaury (snaury)
Date: 2006-02-01 18:29
Message:
Logged In: YES
user_id=1197042
Ooops, sorry, in the example it should be:
print >>sys.stderr, u"<native text>"
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1421664&group_id=5470
More information about the Python-bugs-list
mailing list