[issue1688] Incorrectly displayed non ascii characters in prompt using "input()" - Python 3.0a2

Amaury Forgeot d'Arc report at bugs.python.org
Fri Jan 11 01:19:30 CET 2008


Amaury Forgeot d'Arc added the comment:

Isn't it enough to encode the prompt with the console encoding, instead
of letting the default utf-8 conversion? This patch corrects the issue
on Windows:

Index: ../Python/bltinmodule.c
===================================================================
--- ../Python/bltinmodule.c     (revision 59843)
+++ ../Python/bltinmodule.c     (working copy)
@@ -1358,12 +1358,19 @@
                else
                        Py_DECREF(tmp);
                if (promptarg != NULL) {
-                       po = PyObject_Str(promptarg);
+                       PyObject *stringpo = PyObject_Str(promptarg);
+                       if (stringpo == NULL) {
+                               Py_DECREF(stdin_encoding);
+                               return NULL;
+                       }
+                       po = PyUnicode_AsEncodedString(stringpo,
+                               PyUnicode_AsString(stdin_encoding), NULL);
+                       Py_DECREF(stringpo);
                        if (po == NULL) {
                                Py_DECREF(stdin_encoding);
                                return NULL;
                        }
-                       prompt = PyUnicode_AsString(po);
+                       prompt = PyString_AsString(po);
                        if (prompt == NULL) {
                                Py_DECREF(stdin_encoding);
                                Py_DECREF(po);

__________________________________
Tracker <report at bugs.python.org>
<http://bugs.python.org/issue1688>
__________________________________


More information about the Python-bugs-list mailing list