return 1; /* unknown type; might be path expression */
}
-static PyObject*
-element_extend(ElementObject* self, PyObject* args)
+/*[clinic input]
+_elementtree.Element.extend
+
+ elements: object
+ /
+
+[clinic start generated code]*/
+
+static PyObject *
+_elementtree_Element_extend(ElementObject *self, PyObject *elements)
+/*[clinic end generated code: output=f6e67fc2ff529191 input=807bc4f31c69f7c0]*/
{
PyObject* seq;
- Py_ssize_t i, seqlen = 0;
+ Py_ssize_t i;
- PyObject* seq_in;
- if (!PyArg_ParseTuple(args, "O:extend", &seq_in))
- return NULL;
-
- seq = PySequence_Fast(seq_in, "");
+ seq = PySequence_Fast(elements, "");
if (!seq) {
PyErr_Format(
PyExc_TypeError,
for (i = 0; i < self->extra->length; i++) {
PyObject* item = self->extra->children[i];
- if (Element_CheckExact(item) &&
- PyObject_RichCompareBool(((ElementObject*)item)->tag, path, Py_EQ) == 1) {
- Py_INCREF(item);
+ int rc;
+ if (!Element_CheckExact(item))
+ continue;
+ Py_INCREF(item);
- rc = PyObject_RichCompareBool(((ElementObject*)item)->tag, tag, Py_EQ);
++ rc = PyObject_RichCompareBool(((ElementObject*)item)->tag, path, Py_EQ);
+ if (rc > 0)
return item;
- }
+ Py_DECREF(item);
+ if (rc < 0)
+ return NULL;
}
Py_RETURN_NONE;
for (i = 0; i < self->extra->length; i++) {
ElementObject* item = (ElementObject*) self->extra->children[i];
- if (Element_CheckExact(item) &&
- (PyObject_RichCompareBool(item->tag, path, Py_EQ) == 1)) {
+ int rc;
+ if (!Element_CheckExact(item))
+ continue;
+ Py_INCREF(item);
- rc = PyObject_RichCompareBool(item->tag, tag, Py_EQ);
++ rc = PyObject_RichCompareBool(item->tag, path, Py_EQ);
+ if (rc > 0) {
PyObject* text = element_get_text(item);
- if (text == Py_None)
+ if (text == Py_None) {
+ Py_DECREF(item);
return PyUnicode_New(0, 0);
+ }
Py_XINCREF(text);
+ Py_DECREF(item);
return text;
}
+ Py_DECREF(item);
+ if (rc < 0)
+ return NULL;
}
Py_INCREF(default_value);
return elem;
}
-static PyObject*
-element_remove(ElementObject* self, PyObject* args)
+/*[clinic input]
+_elementtree.Element.remove
+
+ subelement: object(subclass_of='&Element_Type')
+ /
+
+[clinic start generated code]*/
+
+static PyObject *
+_elementtree_Element_remove_impl(ElementObject *self, PyObject *subelement)
+/*[clinic end generated code: output=38fe6c07d6d87d1f input=d52fc28ededc0bd8]*/
{
- int i;
+ Py_ssize_t i;
+ int rc;
- PyObject* element;
- PyObject* found;
-
- if (!PyArg_ParseTuple(args, "O!:remove", &Element_Type, &element))
- return NULL;
++ PyObject *found;
if (!self->extra) {
/* element has no children, so raise exception */
}
for (i = 0; i < self->extra->length; i++) {
- if (self->extra->children[i] == element)
+ if (self->extra->children[i] == subelement)
break;
- if (PyObject_RichCompareBool(self->extra->children[i], subelement, Py_EQ) == 1)
- rc = PyObject_RichCompareBool(self->extra->children[i], element, Py_EQ);
++ rc = PyObject_RichCompareBool(self->extra->children[i], subelement, Py_EQ);
+ if (rc > 0)
break;
+ if (rc < 0)
+ return NULL;
}
- if (i == self->extra->length) {
+ if (i >= self->extra->length) {
- /* element is not in children, so raise exception */
+ /* subelement is not in children, so raise exception */
PyErr_SetString(
PyExc_ValueError,
"list.remove(x): x not in list"