diff options
author | Martin v. Löwis <martin@v.loewis.de> | 2001-09-19 13:47:32 (GMT) |
---|---|---|
committer | Martin v. Löwis <martin@v.loewis.de> | 2001-09-19 13:47:32 (GMT) |
commit | 2777c021fc3bf6d2e33c58b774f8cbeb03ebe78c (patch) | |
tree | 149d8bf2d901aa695f357e2d52e3ce20e13add46 /Objects | |
parent | 5b5e0b9bf9951ebcafcf09354d770905293a32d5 (diff) | |
download | cpython-2777c021fc3bf6d2e33c58b774f8cbeb03ebe78c.zip cpython-2777c021fc3bf6d2e33c58b774f8cbeb03ebe78c.tar.gz cpython-2777c021fc3bf6d2e33c58b774f8cbeb03ebe78c.tar.bz2 |
Patch #462849: Pass Unicode objects to file's .write method.
Diffstat (limited to 'Objects')
-rw-r--r-- | Objects/fileobject.c | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/Objects/fileobject.c b/Objects/fileobject.c index 779b5fa..64bdb65 100644 --- a/Objects/fileobject.c +++ b/Objects/fileobject.c @@ -1503,9 +1503,14 @@ PyFile_WriteObject(PyObject *v, PyObject *f, int flags) writer = PyObject_GetAttrString(f, "write"); if (writer == NULL) return -1; - if (flags & Py_PRINT_RAW) - value = PyObject_Str(v); - else + if (flags & Py_PRINT_RAW) { + if (PyUnicode_Check(v)) { + value = v; + Py_INCREF(value); + } else + value = PyObject_Str(v); + } + else value = PyObject_Repr(v); if (value == NULL) { Py_DECREF(writer); |