[Patches] [ python-Patches-612627 ] Allow more Unicode on sys.stdout

noreply@sourceforge.net noreply@sourceforge.net
Thu, 24 Oct 2002 12:55:19 -0700


Patches item #612627, was opened at 2002-09-21 22:32
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=612627&group_id=5470

Category: Core (C code)
Group: None
Status: Open
Resolution: None
Priority: 5
Submitted By: Martin v. Löwis (loewis)
>Assigned to: M.-A. Lemburg (lemburg)
Summary: Allow more Unicode on sys.stdout

Initial Comment:
This patch extends the set of Unicode strings that can
be printed to sys.stdout, to support all strings that
the terminal will likely support. It also adds an
encoding attribute to sys.std{in,out}.

To do that:
- it adds a .encoding attribute to all file objects,
which is normally None
- initializes the encoding of sys.stdin and sys.stdout
if either is a terminal.
- adds a wrapper object around sys.stdout in site.py
that encodes all Unicode objects according to the
detected encoding, if that encoding is known to Python

To find the encoding of the terminal, it
- uses GetConsoleCP and GetConsoleOutputCP on Windows,
- uses nl_langinfo(CODESET) on Unix, if available.

The primary rationale for this change is that people
should be able to print Unicode in an interactive
session. A parallel change needs to be added for IDLE,
so that it adds the .encoding attribute to the emulated
stdout (it already supports printing of Unicode on stdout).

----------------------------------------------------------------------

Comment By: Martin v. Löwis (loewis)
Date: 2002-09-24 11:02

Message:
Logged In: YES 
user_id=21627

I have considered implementing it in the file object.
However, it becomes quite involved, and heavy C code:
PyFile_WriteObject calls PyObject_Print. Since Unicode does
not implement a tp_print, this calls str/repr, which
converts using the default encoding.

It is not clear at which point the file encoding should be
taking into account.

----------------------------------------------------------------------

Comment By: Nobody/Anonymous (nobody)
Date: 2002-09-24 10:10

Message:
Logged In: NO 

I like the .encoding concept. 

I don't really like the sys.stdout wrapper. Wouldn't it be 
better to add the functionality to the file object .write() and 
.writelines() methods and then only use the wrapper in case 
sys.stdout is not a true file object ?


----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=612627&group_id=5470