mirror of
https://github.com/python/cpython.git
synced 2025-11-01 10:45:30 +00:00
Closes Issue #14246: _elementtree parser will now handle io.StringIO
This commit is contained in:
parent
e53d977e80
commit
f996e775ea
2 changed files with 36 additions and 1 deletions
|
|
@ -2682,6 +2682,7 @@ xmlparser_parse(XMLParserObject* self, PyObject* args)
|
|||
|
||||
PyObject* reader;
|
||||
PyObject* buffer;
|
||||
PyObject* temp;
|
||||
PyObject* res;
|
||||
|
||||
PyObject* fileobj;
|
||||
|
|
@ -2703,7 +2704,27 @@ xmlparser_parse(XMLParserObject* self, PyObject* args)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
if (!PyBytes_CheckExact(buffer) || PyBytes_GET_SIZE(buffer) == 0) {
|
||||
if (PyUnicode_CheckExact(buffer)) {
|
||||
/* A unicode object is encoded into bytes using UTF-8 */
|
||||
if (PyUnicode_GET_SIZE(buffer) == 0) {
|
||||
Py_DECREF(buffer);
|
||||
break;
|
||||
}
|
||||
temp = PyUnicode_AsEncodedString(buffer, "utf-8", "surrogatepass");
|
||||
if (!temp) {
|
||||
/* Propagate exception from PyUnicode_AsEncodedString */
|
||||
Py_DECREF(buffer);
|
||||
Py_DECREF(reader);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Here we no longer need the original buffer since it contains
|
||||
* unicode. Make it point to the encoded bytes object.
|
||||
*/
|
||||
Py_DECREF(buffer);
|
||||
buffer = temp;
|
||||
}
|
||||
else if (!PyBytes_CheckExact(buffer) || PyBytes_GET_SIZE(buffer) == 0) {
|
||||
Py_DECREF(buffer);
|
||||
break;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue