diff Python/bltinmodule.c @ 49261:f0c25e6bbad5

#1688: On Windows, the input() prompt was not correctly displayed if it contains non-ascii characters. Reviewed by Benjamin Peterson.
author Amaury Forgeot d'Arc <amauryfa@gmail.com>
date Sun, 21 Sep 2008 21:49:01 +0000
parents f27ccfdea834
children e822992cf6ce
line wrap: on
line diff
--- a/Python/bltinmodule.c	Sun Sep 21 20:52:42 2008 +0000
+++ b/Python/bltinmodule.c	Sun Sep 21 21:49:01 2008 +0000
@@ -1597,12 +1597,29 @@
 		else
 			Py_DECREF(tmp);
 		if (promptarg != NULL) {
-			po = PyObject_Str(promptarg);
+			PyObject *stringpo;
+			PyObject *stdout_encoding;
+			stdout_encoding = PyObject_GetAttrString(fout,
+								 "encoding");
+			if (stdout_encoding == NULL) {
+				Py_DECREF(stdin_encoding);
+				return NULL;
+			}
+			stringpo = PyObject_Str(promptarg);
+			if (stringpo == NULL) {
+				Py_DECREF(stdin_encoding);
+				Py_DECREF(stdout_encoding);
+				return NULL;
+			}
+			po = PyUnicode_AsEncodedString(stringpo,
+				_PyUnicode_AsString(stdout_encoding), NULL);
+			Py_DECREF(stdout_encoding);
+			Py_DECREF(stringpo);
 			if (po == NULL) {
 				Py_DECREF(stdin_encoding);
 				return NULL;
 			}
-			prompt = _PyUnicode_AsString(po);
+			prompt = PyBytes_AsString(po);
 			if (prompt == NULL) {
 				Py_DECREF(stdin_encoding);
 				Py_DECREF(po);