typedef struct {
- /* attributes (a dictionary object), or None if no attributes */
+ /* attributes (a dictionary object), or NULL if no attributes */
PyObject* attrib;
/* child elements */
return -1;
}
- if (!attrib)
- attrib = Py_None;
-
- Py_INCREF(attrib);
+ Py_XINCREF(attrib);
self->extra->attrib = attrib;
self->extra->length = 0;
if (!extra)
return;
- Py_DECREF(extra->attrib);
+ Py_XDECREF(extra->attrib);
for (i = 0; i < extra->length; i++)
Py_DECREF(extra->children[i]);
ALLOC(sizeof(ElementObject), "create element");
PyObject_GC_Track(self);
- if (attrib != Py_None && !is_empty_dict(attrib)) {
+ if (attrib != NULL && !is_empty_dict(attrib)) {
if (create_extra(self, attrib) < 0) {
Py_DECREF(self);
return NULL;
PyObject* res = self->extra->attrib;
- if (res == Py_None) {
+ if (!res) {
/* create missing dictionary */
- res = PyDict_New();
- if (!res)
- return NULL;
- Py_DECREF(Py_None);
- self->extra->attrib = res;
+ res = self->extra->attrib = PyDict_New();
}
return res;
return NULL;
} else {
/* no attrib arg, no kwds, so no attribute */
- Py_INCREF(Py_None);
- attrib = Py_None;
}
elem = create_new_element(tag, attrib);
- Py_DECREF(attrib);
+ Py_XDECREF(attrib);
if (elem == NULL)
return NULL;
ElementObject* element;
element = (ElementObject*) create_new_element(
- self->tag, (self->extra) ? self->extra->attrib : Py_None);
+ self->tag, self->extra ? self->extra->attrib : NULL);
if (!element)
return NULL;
if (!tag)
return NULL;
- if (self->extra) {
+ if (self->extra && self->extra->attrib) {
attrib = deepcopy(self->extra->attrib, memo);
if (!attrib) {
Py_DECREF(tag);
return NULL;
}
} else {
- Py_INCREF(Py_None);
- attrib = Py_None;
+ attrib = NULL;
}
element = (ElementObject*) create_new_element(tag, attrib);
Py_DECREF(tag);
- Py_DECREF(attrib);
+ Py_XDECREF(attrib);
if (!element)
return NULL;
PyList_SET_ITEM(children, i, child);
}
- if (self->extra && self->extra->attrib != Py_None) {
+ if (self->extra && self->extra->attrib) {
attrib = self->extra->attrib;
Py_INCREF(attrib);
}
assert(self->extra);
assert(self->extra->allocated >= nchildren);
if (oldextra) {
- assert(self->extra->attrib == Py_None);
+ assert(self->extra->attrib == NULL);
self->extra->attrib = oldextra->attrib;
- oldextra->attrib = Py_None;
+ oldextra->attrib = NULL;
}
/* Copy children */
}
/* Stash attrib. */
- if (attrib) {
- Py_INCREF(attrib);
- Py_XSETREF(self->extra->attrib, attrib);
- }
+ Py_XINCREF(attrib);
+ Py_XSETREF(self->extra->attrib, attrib);
dealloc_extra(oldextra);
Py_RETURN_NONE;
{
PyObject* value;
- if (!self->extra || self->extra->attrib == Py_None)
+ if (!self->extra || !self->extra->attrib)
value = default_value;
else {
value = PyDict_GetItemWithError(self->extra->attrib, key);
_elementtree_Element_items_impl(ElementObject *self)
/*[clinic end generated code: output=6db2c778ce3f5a4d input=adbe09aaea474447]*/
{
- if (!self->extra || self->extra->attrib == Py_None)
+ if (!self->extra || !self->extra->attrib)
return PyList_New(0);
return PyDict_Items(self->extra->attrib);
_elementtree_Element_keys_impl(ElementObject *self)
/*[clinic end generated code: output=bc5bfabbf20eeb3c input=f02caf5b496b5b0b]*/
{
- if (!self->extra || self->extra->attrib == Py_None)
+ if (!self->extra || !self->extra->attrib)
return PyList_New(0);
return PyDict_Keys(self->extra->attrib);
_elementtree.Element.makeelement
tag: object
- attrib: object
+ attrib: object(subclass_of='&PyDict_Type')
/
[clinic start generated code]*/
static PyObject *
_elementtree_Element_makeelement_impl(ElementObject *self, PyObject *tag,
PyObject *attrib)
-/*[clinic end generated code: output=4109832d5bb789ef input=9480d1d2e3e68235]*/
+/*[clinic end generated code: output=4109832d5bb789ef input=2279d974529c3861]*/
{
PyObject* elem;
element_attrib_setter(ElementObject *self, PyObject *value, void *closure)
{
_VALIDATE_ATTR_VALUE(value);
+ if (!PyDict_Check(value)) {
+ PyErr_Format(PyExc_TypeError,
+ "attrib must be dict, not %.200s",
+ value->ob_type->tp_name);
+ return -1;
+ }
if (!self->extra) {
if (create_extra(self, NULL) < 0)
return -1;
}
Py_INCREF(value);
- Py_SETREF(self->extra->attrib, value);
+ Py_XSETREF(self->extra->attrib, value);
return 0;
}
if (!self->element_factory) {
node = create_new_element(tag, attrib);
- } else if (attrib == Py_None) {
+ } else if (attrib == NULL) {
attrib = PyDict_New();
if (!attrib)
return NULL;
attrib_in += 2;
}
} else {
- Py_INCREF(Py_None);
- attrib = Py_None;
+ attrib = NULL;
}
if (TreeBuilder_CheckExact(self->target)) {
tag, attrib);
}
else if (self->handle_start) {
- if (attrib == Py_None) {
- Py_DECREF(attrib);
+ if (attrib == NULL) {
attrib = PyDict_New();
if (!attrib) {
Py_DECREF(tag);
res = NULL;
Py_DECREF(tag);
- Py_DECREF(attrib);
+ Py_XDECREF(attrib);
Py_XDECREF(res);
}