summaryrefslogtreecommitdiffstats
path: root/Objects/fileobject.c
diff options
context:
space:
mode:
Diffstat (limited to 'Objects/fileobject.c')
-rw-r--r--Objects/fileobject.c11
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);