mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
Allow PyFile_GetLine() to return Unicode objects. Fixes #660165.
This commit is contained in:
parent
bb0246ac25
commit
af6a27a704
2 changed files with 26 additions and 1 deletions
|
@ -12,6 +12,8 @@ What's New in Python 2.3 alpha 2?
|
||||||
Core and builtins
|
Core and builtins
|
||||||
-----------------
|
-----------------
|
||||||
|
|
||||||
|
- raw_input can now return Unicode objects.
|
||||||
|
|
||||||
- List objects' sort() method now accepts None as the comparison function.
|
- List objects' sort() method now accepts None as the comparison function.
|
||||||
Passing None is semantically identical to calling sort() with no
|
Passing None is semantically identical to calling sort() with no
|
||||||
arguments.
|
arguments.
|
||||||
|
|
|
@ -1212,7 +1212,8 @@ PyFile_GetLine(PyObject *f, int n)
|
||||||
result = PyEval_CallObject(reader, args);
|
result = PyEval_CallObject(reader, args);
|
||||||
Py_DECREF(reader);
|
Py_DECREF(reader);
|
||||||
Py_DECREF(args);
|
Py_DECREF(args);
|
||||||
if (result != NULL && !PyString_Check(result)) {
|
if (result != NULL && !PyString_Check(result) &&
|
||||||
|
!PyUnicode_Check(result)) {
|
||||||
Py_DECREF(result);
|
Py_DECREF(result);
|
||||||
result = NULL;
|
result = NULL;
|
||||||
PyErr_SetString(PyExc_TypeError,
|
PyErr_SetString(PyExc_TypeError,
|
||||||
|
@ -1240,6 +1241,28 @@ PyFile_GetLine(PyObject *f, int n)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#ifdef Py_USING_UNICODE
|
||||||
|
if (n < 0 && result != NULL && PyUnicode_Check(result)) {
|
||||||
|
Py_UNICODE *s = PyUnicode_AS_UNICODE(result);
|
||||||
|
int len = PyUnicode_GET_SIZE(result);
|
||||||
|
if (len == 0) {
|
||||||
|
Py_DECREF(result);
|
||||||
|
result = NULL;
|
||||||
|
PyErr_SetString(PyExc_EOFError,
|
||||||
|
"EOF when reading a line");
|
||||||
|
}
|
||||||
|
else if (s[len-1] == '\n') {
|
||||||
|
if (result->ob_refcnt == 1)
|
||||||
|
PyUnicode_Resize(&result, len-1);
|
||||||
|
else {
|
||||||
|
PyObject *v;
|
||||||
|
v = PyUnicode_FromUnicode(s, len-1);
|
||||||
|
Py_DECREF(result);
|
||||||
|
result = v;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue