mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
Patch #462849: Pass Unicode objects to file's .write method.
This commit is contained in:
parent
5b5e0b9bf9
commit
2777c021fc
2 changed files with 13 additions and 3 deletions
|
@ -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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue