[ python-Bugs-1421664 ] [win32] stderr atty encoding not set

SourceForge.net noreply at sourceforge.net
Wed Feb 1 18:29:50 CET 2006


Bugs item #1421664, was opened at 2006-02-01 20:25
Message generated for change (Comment added) made by snaury
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: Open
Resolution: None
Priority: 5
Submitted By: Snaury (snaury)
Assigned to: Nobody/Anonymous (nobody)
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: Snaury (snaury)
Date: 2006-02-01 20: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