diff options
author | Martin v. Löwis <martin@v.loewis.de> | 2007-09-04 05:24:49 (GMT) |
---|---|---|
committer | Martin v. Löwis <martin@v.loewis.de> | 2007-09-04 05:24:49 (GMT) |
commit | 4a7b5d5b4fa00da3af075fd21ea21caa3d434609 (patch) | |
tree | 38df0033d9ed4f3b2a1c92a7d7f6ee4c341b2ea6 /Python | |
parent | 4edae68f2f02bcfadc8de81616566a18df20a3e8 (diff) | |
download | cpython-4a7b5d5b4fa00da3af075fd21ea21caa3d434609.zip cpython-4a7b5d5b4fa00da3af075fd21ea21caa3d434609.tar.gz cpython-4a7b5d5b4fa00da3af075fd21ea21caa3d434609.tar.bz2 |
Decode input() with stdin.encoding. Fixes #1097.
Diffstat (limited to 'Python')
-rw-r--r-- | Python/bltinmodule.c | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c index 6675abf..9179a42 100644 --- a/Python/bltinmodule.c +++ b/Python/bltinmodule.c @@ -1314,7 +1314,14 @@ builtin_input(PyObject *self, PyObject *args) PyObject *po; char *prompt; char *s; + PyObject *stdin_encoding; PyObject *result; + + stdin_encoding = PyObject_GetAttrString(fin, "encoding"); + if (!stdin_encoding) + /* stdin is a text stream, so it must have an + encoding. */ + return NULL; tmp = PyObject_CallMethod(fout, "flush", ""); if (tmp == NULL) PyErr_Clear(); @@ -1322,10 +1329,13 @@ builtin_input(PyObject *self, PyObject *args) Py_DECREF(tmp); if (promptarg != NULL) { po = PyObject_Str(promptarg); - if (po == NULL) + if (po == NULL) { + Py_DECREF(stdin_encoding); return NULL; + } prompt = PyString_AsString(po); if (prompt == NULL) { + Py_DECREF(stdin_encoding); Py_DECREF(po); return NULL; } @@ -1339,6 +1349,7 @@ builtin_input(PyObject *self, PyObject *args) if (s == NULL) { if (!PyErr_Occurred()) PyErr_SetNone(PyExc_KeyboardInterrupt); + Py_DECREF(stdin_encoding); return NULL; } if (*s == '\0') { @@ -1353,9 +1364,13 @@ builtin_input(PyObject *self, PyObject *args) result = NULL; } else { - result = PyUnicode_FromStringAndSize(s, len-1); + result = PyUnicode_Decode + (s, len-1, + PyUnicode_AsString(stdin_encoding), + NULL); } } + Py_DECREF(stdin_encoding); PyMem_FREE(s); return result; } |