Kaydet (Commit) 2777c021 authored tarafından Martin v. Löwis's avatar Martin v. Löwis

Patch #462849: Pass Unicode objects to file's .write method.

üst 5b5e0b9b
...@@ -3,6 +3,11 @@ What's New in Python 2.2a4? ...@@ -3,6 +3,11 @@ What's New in Python 2.2a4?
Core Core
- PyFile_WriteObject now passes Unicode object to the file's write
method. As a result, all file-like object which may be the target
of a print statement must support Unicode objects, i.e. they must
at least convert them into ASCII strings.
- The builtin file type can be subclassed now. In the usual pattern, - The builtin file type can be subclassed now. In the usual pattern,
"file" is the name of the builtin type, and file() is a new builtin "file" is the name of the builtin type, and file() is a new builtin
constructor, with the same signature as the builtin open() function. constructor, with the same signature as the builtin open() function.
......
...@@ -1503,8 +1503,13 @@ PyFile_WriteObject(PyObject *v, PyObject *f, int flags) ...@@ -1503,8 +1503,13 @@ PyFile_WriteObject(PyObject *v, PyObject *f, int flags)
writer = PyObject_GetAttrString(f, "write"); writer = PyObject_GetAttrString(f, "write");
if (writer == NULL) if (writer == NULL)
return -1; return -1;
if (flags & Py_PRINT_RAW) if (flags & Py_PRINT_RAW) {
if (PyUnicode_Check(v)) {
value = v;
Py_INCREF(value);
} else
value = PyObject_Str(v); value = PyObject_Str(v);
}
else else
value = PyObject_Repr(v); value = PyObject_Repr(v);
if (value == NULL) { if (value == NULL) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment