gh-92123: Adapt _elementtree to multi-phase init (PEP 489) (#101285)

This commit is contained in:
Erlend E. Aasland 2023-01-24 17:00:24 +01:00 committed by GitHub
parent 00d092caa8
commit fee7a995a1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 280 additions and 130 deletions

View File

@ -0,0 +1,2 @@
Adapt the ``_elementtree`` extension module to multi-phase init (:pep:`489`).
Patches by Erlend E. Aasland.

View File

@ -105,11 +105,21 @@ get_elementtree_state(PyObject *module)
return (elementtreestate *)state; return (elementtreestate *)state;
} }
/* Find the module instance imported in the currently running sub-interpreter static inline elementtreestate *
* and get its state. get_elementtree_state_by_cls(PyTypeObject *cls)
*/ {
#define ET_STATE_GLOBAL \ void *state = PyType_GetModuleState(cls);
((elementtreestate *) PyModule_GetState(PyState_FindModule(&elementtreemodule))) assert(state != NULL);
return (elementtreestate *)state;
}
static inline elementtreestate *
get_elementtree_state_by_type(PyTypeObject *tp)
{
PyObject *mod = PyType_GetModuleByDef(tp, &elementtreemodule);
assert(mod != NULL);
return get_elementtree_state(mod);
}
static int static int
elementtree_clear(PyObject *m) elementtree_clear(PyObject *m)
@ -585,7 +595,7 @@ subelement(PyObject *self, PyObject *args, PyObject *kwds)
{ {
PyObject* elem; PyObject* elem;
elementtreestate *st = ET_STATE_GLOBAL; elementtreestate *st = get_elementtree_state(self);
ElementObject* parent; ElementObject* parent;
PyObject* tag; PyObject* tag;
PyObject* attrib = NULL; PyObject* attrib = NULL;
@ -684,16 +694,18 @@ element_dealloc(ElementObject* self)
/*[clinic input] /*[clinic input]
_elementtree.Element.append _elementtree.Element.append
cls: defining_class
subelement: object(subclass_of='clinic_state()->Element_Type') subelement: object(subclass_of='clinic_state()->Element_Type')
/ /
[clinic start generated code]*/ [clinic start generated code]*/
static PyObject * static PyObject *
_elementtree_Element_append_impl(ElementObject *self, PyObject *subelement) _elementtree_Element_append_impl(ElementObject *self, PyTypeObject *cls,
/*[clinic end generated code: output=54a884b7cf2295f4 input=439f2bd777288fb6]*/ PyObject *subelement)
/*[clinic end generated code: output=d00923711ea317fc input=8baf92679f9717b8]*/
{ {
elementtreestate *st = ET_STATE_GLOBAL; elementtreestate *st = get_elementtree_state_by_cls(cls);
if (element_add_subelement(st, self, subelement) < 0) if (element_add_subelement(st, self, subelement) < 0)
return NULL; return NULL;
@ -720,15 +732,18 @@ _elementtree_Element_clear_impl(ElementObject *self)
/*[clinic input] /*[clinic input]
_elementtree.Element.__copy__ _elementtree.Element.__copy__
cls: defining_class
/
[clinic start generated code]*/ [clinic start generated code]*/
static PyObject * static PyObject *
_elementtree_Element___copy___impl(ElementObject *self) _elementtree_Element___copy___impl(ElementObject *self, PyTypeObject *cls)
/*[clinic end generated code: output=2c701ebff7247781 input=ad87aaebe95675bf]*/ /*[clinic end generated code: output=da22894421ff2b36 input=91edb92d9f441213]*/
{ {
Py_ssize_t i; Py_ssize_t i;
ElementObject* element; ElementObject* element;
elementtreestate *st = ET_STATE_GLOBAL; elementtreestate *st = get_elementtree_state_by_cls(cls);
element = (ElementObject*) create_new_element( element = (ElementObject*) create_new_element(
st, self->tag, self->extra ? self->extra->attrib : NULL); st, self->tag, self->extra ? self->extra->attrib : NULL);
@ -782,7 +797,8 @@ _elementtree_Element___deepcopy___impl(ElementObject *self, PyObject *memo)
PyObject* tail; PyObject* tail;
PyObject* id; PyObject* id;
elementtreestate *st = ET_STATE_GLOBAL; PyTypeObject *tp = Py_TYPE(self);
elementtreestate *st = get_elementtree_state_by_type(tp);
tag = deepcopy(st, self->tag, memo); tag = deepcopy(st, self->tag, memo);
if (!tag) if (!tag)
return NULL; return NULL;
@ -1093,14 +1109,16 @@ element_setstate_from_Python(elementtreestate *st, ElementObject *self,
/*[clinic input] /*[clinic input]
_elementtree.Element.__setstate__ _elementtree.Element.__setstate__
cls: defining_class
state: object state: object
/ /
[clinic start generated code]*/ [clinic start generated code]*/
static PyObject * static PyObject *
_elementtree_Element___setstate__(ElementObject *self, PyObject *state) _elementtree_Element___setstate___impl(ElementObject *self,
/*[clinic end generated code: output=ea28bf3491b1f75e input=aaf80abea7c1e3b9]*/ PyTypeObject *cls, PyObject *state)
/*[clinic end generated code: output=598bfb5730f71509 input=13830488d35d51f7]*/
{ {
if (!PyDict_CheckExact(state)) { if (!PyDict_CheckExact(state)) {
PyErr_Format(PyExc_TypeError, PyErr_Format(PyExc_TypeError,
@ -1109,7 +1127,7 @@ _elementtree_Element___setstate__(ElementObject *self, PyObject *state)
return NULL; return NULL;
} }
else { else {
elementtreestate *st = ET_STATE_GLOBAL; elementtreestate *st = get_elementtree_state_by_cls(cls);
return element_setstate_from_Python(st, self, state); return element_setstate_from_Python(st, self, state);
} }
} }
@ -1172,14 +1190,16 @@ checkpath(PyObject* tag)
/*[clinic input] /*[clinic input]
_elementtree.Element.extend _elementtree.Element.extend
cls: defining_class
elements: object elements: object
/ /
[clinic start generated code]*/ [clinic start generated code]*/
static PyObject * static PyObject *
_elementtree_Element_extend(ElementObject *self, PyObject *elements) _elementtree_Element_extend_impl(ElementObject *self, PyTypeObject *cls,
/*[clinic end generated code: output=f6e67fc2ff529191 input=807bc4f31c69f7c0]*/ PyObject *elements)
/*[clinic end generated code: output=3e86d37fac542216 input=6479b1b5379d09ae]*/
{ {
PyObject* seq; PyObject* seq;
Py_ssize_t i; Py_ssize_t i;
@ -1193,7 +1213,7 @@ _elementtree_Element_extend(ElementObject *self, PyObject *elements)
return NULL; return NULL;
} }
elementtreestate *st = ET_STATE_GLOBAL; elementtreestate *st = get_elementtree_state_by_cls(cls);
for (i = 0; i < PySequence_Fast_GET_SIZE(seq); i++) { for (i = 0; i < PySequence_Fast_GET_SIZE(seq); i++) {
PyObject* element = Py_NewRef(PySequence_Fast_GET_ITEM(seq, i)); PyObject* element = Py_NewRef(PySequence_Fast_GET_ITEM(seq, i));
if (element_add_subelement(st, self, element) < 0) { if (element_add_subelement(st, self, element) < 0) {
@ -1212,18 +1232,20 @@ _elementtree_Element_extend(ElementObject *self, PyObject *elements)
/*[clinic input] /*[clinic input]
_elementtree.Element.find _elementtree.Element.find
cls: defining_class
/
path: object path: object
namespaces: object = None namespaces: object = None
[clinic start generated code]*/ [clinic start generated code]*/
static PyObject * static PyObject *
_elementtree_Element_find_impl(ElementObject *self, PyObject *path, _elementtree_Element_find_impl(ElementObject *self, PyTypeObject *cls,
PyObject *namespaces) PyObject *path, PyObject *namespaces)
/*[clinic end generated code: output=41b43f0f0becafae input=359b6985f6489d2e]*/ /*[clinic end generated code: output=18f77d393c9fef1b input=94df8a83f956acc6]*/
{ {
Py_ssize_t i; Py_ssize_t i;
elementtreestate *st = ET_STATE_GLOBAL; elementtreestate *st = get_elementtree_state_by_cls(cls);
if (checkpath(path) || namespaces != Py_None) { if (checkpath(path) || namespaces != Py_None) {
return PyObject_CallMethodObjArgs( return PyObject_CallMethodObjArgs(
@ -1253,6 +1275,8 @@ _elementtree_Element_find_impl(ElementObject *self, PyObject *path,
/*[clinic input] /*[clinic input]
_elementtree.Element.findtext _elementtree.Element.findtext
cls: defining_class
/
path: object path: object
default: object = None default: object = None
namespaces: object = None namespaces: object = None
@ -1260,13 +1284,13 @@ _elementtree.Element.findtext
[clinic start generated code]*/ [clinic start generated code]*/
static PyObject * static PyObject *
_elementtree_Element_findtext_impl(ElementObject *self, PyObject *path, _elementtree_Element_findtext_impl(ElementObject *self, PyTypeObject *cls,
PyObject *default_value, PyObject *path, PyObject *default_value,
PyObject *namespaces) PyObject *namespaces)
/*[clinic end generated code: output=83b3ba4535d308d2 input=b53a85aa5aa2a916]*/ /*[clinic end generated code: output=6af7a2d96aac32cb input=32f252099f62a3d2]*/
{ {
Py_ssize_t i; Py_ssize_t i;
elementtreestate *st = ET_STATE_GLOBAL; elementtreestate *st = get_elementtree_state_by_cls(cls);
if (checkpath(path) || namespaces != Py_None) if (checkpath(path) || namespaces != Py_None)
return PyObject_CallMethodObjArgs( return PyObject_CallMethodObjArgs(
@ -1305,19 +1329,21 @@ _elementtree_Element_findtext_impl(ElementObject *self, PyObject *path,
/*[clinic input] /*[clinic input]
_elementtree.Element.findall _elementtree.Element.findall
cls: defining_class
/
path: object path: object
namespaces: object = None namespaces: object = None
[clinic start generated code]*/ [clinic start generated code]*/
static PyObject * static PyObject *
_elementtree_Element_findall_impl(ElementObject *self, PyObject *path, _elementtree_Element_findall_impl(ElementObject *self, PyTypeObject *cls,
PyObject *namespaces) PyObject *path, PyObject *namespaces)
/*[clinic end generated code: output=1a0bd9f5541b711d input=4d9e6505a638550c]*/ /*[clinic end generated code: output=65e39a1208f3b59e input=7aa0db45673fc9a5]*/
{ {
Py_ssize_t i; Py_ssize_t i;
PyObject* out; PyObject* out;
elementtreestate *st = ET_STATE_GLOBAL; elementtreestate *st = get_elementtree_state_by_cls(cls);
if (checkpath(path) || namespaces != Py_None) { if (checkpath(path) || namespaces != Py_None) {
return PyObject_CallMethodObjArgs( return PyObject_CallMethodObjArgs(
@ -1352,18 +1378,20 @@ _elementtree_Element_findall_impl(ElementObject *self, PyObject *path,
/*[clinic input] /*[clinic input]
_elementtree.Element.iterfind _elementtree.Element.iterfind
cls: defining_class
/
path: object path: object
namespaces: object = None namespaces: object = None
[clinic start generated code]*/ [clinic start generated code]*/
static PyObject * static PyObject *
_elementtree_Element_iterfind_impl(ElementObject *self, PyObject *path, _elementtree_Element_iterfind_impl(ElementObject *self, PyTypeObject *cls,
PyObject *namespaces) PyObject *path, PyObject *namespaces)
/*[clinic end generated code: output=ecdd56d63b19d40f input=abb974e350fb65c7]*/ /*[clinic end generated code: output=be5c3f697a14e676 input=88766875a5c9a88b]*/
{ {
PyObject* tag = path; PyObject* tag = path;
elementtreestate *st = ET_STATE_GLOBAL; elementtreestate *st = get_elementtree_state_by_cls(cls);
return PyObject_CallMethodObjArgs( return PyObject_CallMethodObjArgs(
st->elementpath_obj, st->str_iterfind, self, tag, namespaces, NULL); st->elementpath_obj, st->str_iterfind, self, tag, namespaces, NULL);
@ -1402,13 +1430,16 @@ create_elementiter(elementtreestate *st, ElementObject *self, PyObject *tag,
/*[clinic input] /*[clinic input]
_elementtree.Element.iter _elementtree.Element.iter
cls: defining_class
/
tag: object = None tag: object = None
[clinic start generated code]*/ [clinic start generated code]*/
static PyObject * static PyObject *
_elementtree_Element_iter_impl(ElementObject *self, PyObject *tag) _elementtree_Element_iter_impl(ElementObject *self, PyTypeObject *cls,
/*[clinic end generated code: output=3f49f9a862941cc5 input=774d5b12e573aedd]*/ PyObject *tag)
/*[clinic end generated code: output=bff29dc5d4566c68 input=f6944c48d3f84c58]*/
{ {
if (PyUnicode_Check(tag)) { if (PyUnicode_Check(tag)) {
if (PyUnicode_READY(tag) < 0) if (PyUnicode_READY(tag) < 0)
@ -1421,7 +1452,7 @@ _elementtree_Element_iter_impl(ElementObject *self, PyObject *tag)
tag = Py_None; tag = Py_None;
} }
elementtreestate *st = ET_STATE_GLOBAL; elementtreestate *st = get_elementtree_state_by_cls(cls);
return create_elementiter(st, self, tag, 0); return create_elementiter(st, self, tag, 0);
} }
@ -1429,13 +1460,16 @@ _elementtree_Element_iter_impl(ElementObject *self, PyObject *tag)
/*[clinic input] /*[clinic input]
_elementtree.Element.itertext _elementtree.Element.itertext
cls: defining_class
/
[clinic start generated code]*/ [clinic start generated code]*/
static PyObject * static PyObject *
_elementtree_Element_itertext_impl(ElementObject *self) _elementtree_Element_itertext_impl(ElementObject *self, PyTypeObject *cls)
/*[clinic end generated code: output=5fa34b2fbcb65df6 input=af8f0e42cb239c89]*/ /*[clinic end generated code: output=fdeb2a3bca0ae063 input=a1ef1f0fc872a586]*/
{ {
elementtreestate *st = ET_STATE_GLOBAL; elementtreestate *st = get_elementtree_state_by_cls(cls);
return create_elementiter(st, self, Py_None, 1); return create_elementiter(st, self, Py_None, 1);
} }
@ -1557,6 +1591,7 @@ element_length(ElementObject* self)
/*[clinic input] /*[clinic input]
_elementtree.Element.makeelement _elementtree.Element.makeelement
cls: defining_class
tag: object tag: object
attrib: object(subclass_of='&PyDict_Type') attrib: object(subclass_of='&PyDict_Type')
/ /
@ -1564,9 +1599,9 @@ _elementtree.Element.makeelement
[clinic start generated code]*/ [clinic start generated code]*/
static PyObject * static PyObject *
_elementtree_Element_makeelement_impl(ElementObject *self, PyObject *tag, _elementtree_Element_makeelement_impl(ElementObject *self, PyTypeObject *cls,
PyObject *attrib) PyObject *tag, PyObject *attrib)
/*[clinic end generated code: output=4109832d5bb789ef input=2279d974529c3861]*/ /*[clinic end generated code: output=d50bb17a47077d47 input=589829dab92f26e8]*/
{ {
PyObject* elem; PyObject* elem;
@ -1574,7 +1609,7 @@ _elementtree_Element_makeelement_impl(ElementObject *self, PyObject *tag,
if (!attrib) if (!attrib)
return NULL; return NULL;
elementtreestate *st = ET_STATE_GLOBAL; elementtreestate *st = get_elementtree_state_by_cls(cls);
elem = create_new_element(st, tag, attrib); elem = create_new_element(st, tag, attrib);
Py_DECREF(attrib); Py_DECREF(attrib);
@ -1706,7 +1741,8 @@ element_setitem(PyObject* self_, Py_ssize_t index, PyObject* item)
old = self->extra->children[index]; old = self->extra->children[index];
if (item) { if (item) {
elementtreestate *st = ET_STATE_GLOBAL; PyTypeObject *tp = Py_TYPE(self);
elementtreestate *st = get_elementtree_state_by_type(tp);
if (!Element_Check(st, item)) { if (!Element_Check(st, item)) {
raise_type_error(item); raise_type_error(item);
return -1; return -1;
@ -1904,7 +1940,8 @@ element_ass_subscr(PyObject* self_, PyObject* item, PyObject* value)
} }
} }
elementtreestate *st = ET_STATE_GLOBAL; PyTypeObject *tp = Py_TYPE(self);
elementtreestate *st = get_elementtree_state_by_type(tp);
for (i = 0; i < newlen; i++) { for (i = 0; i < newlen; i++) {
PyObject *element = PySequence_Fast_GET_ITEM(seq, i); PyObject *element = PySequence_Fast_GET_ITEM(seq, i);
if (!Element_Check(st, element)) { if (!Element_Check(st, element)) {
@ -2181,7 +2218,8 @@ elementiter_next(ElementIterObject *it)
} }
#ifndef NDEBUG #ifndef NDEBUG
elementtreestate *st = ET_STATE_GLOBAL; PyTypeObject *tp = Py_TYPE(it);
elementtreestate *st = get_elementtree_state_by_type(tp);
assert(Element_Check(st, extra->children[child_index])); assert(Element_Check(st, extra->children[child_index]));
#endif #endif
elem = (ElementObject *)Py_NewRef(extra->children[child_index]); elem = (ElementObject *)Py_NewRef(extra->children[child_index]);
@ -2348,7 +2386,7 @@ treebuilder_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
t->start_ns_event_obj = t->end_ns_event_obj = NULL; t->start_ns_event_obj = t->end_ns_event_obj = NULL;
t->comment_event_obj = t->pi_event_obj = NULL; t->comment_event_obj = t->pi_event_obj = NULL;
t->insert_comments = t->insert_pis = 0; t->insert_comments = t->insert_pis = 0;
t->state = ET_STATE_GLOBAL; t->state = get_elementtree_state_by_type(type);
} }
return (PyObject *)t; return (PyObject *)t;
} }
@ -2481,7 +2519,7 @@ _elementtree__set_factories_impl(PyObject *module, PyObject *comment_factory,
PyObject *pi_factory) PyObject *pi_factory)
/*[clinic end generated code: output=813b408adee26535 input=99d17627aea7fb3b]*/ /*[clinic end generated code: output=813b408adee26535 input=99d17627aea7fb3b]*/
{ {
elementtreestate *st = ET_STATE_GLOBAL; elementtreestate *st = get_elementtree_state(module);
PyObject *old; PyObject *old;
if (!PyCallable_Check(comment_factory) && comment_factory != Py_None) { if (!PyCallable_Check(comment_factory) && comment_factory != Py_None) {
@ -3570,7 +3608,7 @@ xmlparser_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
self->handle_start = self->handle_data = self->handle_end = NULL; self->handle_start = self->handle_data = self->handle_end = NULL;
self->handle_comment = self->handle_pi = self->handle_close = NULL; self->handle_comment = self->handle_pi = self->handle_close = NULL;
self->handle_doctype = NULL; self->handle_doctype = NULL;
self->state = ET_STATE_GLOBAL; self->state = get_elementtree_state_by_type(type);
} }
return (PyObject *)self; return (PyObject *)self;
} }
@ -4115,7 +4153,7 @@ static PyGetSetDef xmlparser_getsetlist[] = {
{NULL}, {NULL},
}; };
#define clinic_state() (ET_STATE_GLOBAL) #define clinic_state() (get_elementtree_state_by_type(Py_TYPE(self)))
#include "clinic/_elementtree.c.h" #include "clinic/_elementtree.c.h"
#undef clinic_state #undef clinic_state
@ -4274,19 +4312,6 @@ static PyMethodDef _functions[] = {
{NULL, NULL} {NULL, NULL}
}; };
static struct PyModuleDef elementtreemodule = {
PyModuleDef_HEAD_INIT,
"_elementtree",
NULL,
sizeof(elementtreestate),
_functions,
NULL,
elementtree_traverse,
elementtree_clear,
elementtree_free
};
#define CREATE_TYPE(module, type, spec) \ #define CREATE_TYPE(module, type, spec) \
do { \ do { \
if (type != NULL) { \ if (type != NULL) { \
@ -4298,21 +4323,10 @@ do { \
} \ } \
} while (0) } while (0)
PyMODINIT_FUNC static int
PyInit__elementtree(void) module_exec(PyObject *m)
{ {
PyObject *m = NULL; elementtreestate *st = get_elementtree_state(m);
elementtreestate *st = NULL;
m = PyState_FindModule(&elementtreemodule);
if (m) {
return Py_NewRef(m);
}
m = PyModule_Create(&elementtreemodule);
if (!m)
goto error;
st = get_elementtree_state(m);
/* Initialize object types */ /* Initialize object types */
CREATE_TYPE(m, st->ElementIter_Type, &elementiter_spec); CREATE_TYPE(m, st->ElementIter_Type, &elementiter_spec);
@ -4397,9 +4411,30 @@ PyInit__elementtree(void)
} }
} }
return m; return 0;
error: error:
Py_XDECREF(m); return -1;
return NULL; }
static struct PyModuleDef_Slot elementtree_slots[] = {
{Py_mod_exec, module_exec},
{0, NULL},
};
static struct PyModuleDef elementtreemodule = {
.m_base = PyModuleDef_HEAD_INIT,
.m_name = "_elementtree",
.m_size = sizeof(elementtreestate),
.m_methods = _functions,
.m_slots = elementtree_slots,
.m_traverse = elementtree_traverse,
.m_clear = elementtree_clear,
.m_free = elementtree_free,
};
PyMODINIT_FUNC
PyInit__elementtree(void)
{
return PyModuleDef_Init(&elementtreemodule);
} }

View File

@ -14,23 +14,42 @@ PyDoc_STRVAR(_elementtree_Element_append__doc__,
"\n"); "\n");
#define _ELEMENTTREE_ELEMENT_APPEND_METHODDEF \ #define _ELEMENTTREE_ELEMENT_APPEND_METHODDEF \
{"append", (PyCFunction)_elementtree_Element_append, METH_O, _elementtree_Element_append__doc__}, {"append", _PyCFunction_CAST(_elementtree_Element_append), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _elementtree_Element_append__doc__},
static PyObject * static PyObject *
_elementtree_Element_append_impl(ElementObject *self, PyObject *subelement); _elementtree_Element_append_impl(ElementObject *self, PyTypeObject *cls,
PyObject *subelement);
static PyObject * static PyObject *
_elementtree_Element_append(ElementObject *self, PyObject *arg) _elementtree_Element_append(ElementObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{ {
PyObject *return_value = NULL; PyObject *return_value = NULL;
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
# define KWTUPLE (PyObject *)&_Py_SINGLETON(tuple_empty)
#else
# define KWTUPLE NULL
#endif
static const char * const _keywords[] = {"", NULL};
static _PyArg_Parser _parser = {
.keywords = _keywords,
.fname = "append",
.kwtuple = KWTUPLE,
};
#undef KWTUPLE
PyObject *argsbuf[1];
PyObject *subelement; PyObject *subelement;
if (!PyObject_TypeCheck(arg, clinic_state()->Element_Type)) { args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
_PyArg_BadArgument("append", "argument", (clinic_state()->Element_Type)->tp_name, arg); if (!args) {
goto exit; goto exit;
} }
subelement = arg; if (!PyObject_TypeCheck(args[0], clinic_state()->Element_Type)) {
return_value = _elementtree_Element_append_impl(self, subelement); _PyArg_BadArgument("append", "argument 1", (clinic_state()->Element_Type)->tp_name, args[0]);
goto exit;
}
subelement = args[0];
return_value = _elementtree_Element_append_impl(self, cls, subelement);
exit: exit:
return return_value; return return_value;
@ -59,15 +78,19 @@ PyDoc_STRVAR(_elementtree_Element___copy____doc__,
"\n"); "\n");
#define _ELEMENTTREE_ELEMENT___COPY___METHODDEF \ #define _ELEMENTTREE_ELEMENT___COPY___METHODDEF \
{"__copy__", (PyCFunction)_elementtree_Element___copy__, METH_NOARGS, _elementtree_Element___copy____doc__}, {"__copy__", _PyCFunction_CAST(_elementtree_Element___copy__), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _elementtree_Element___copy____doc__},
static PyObject * static PyObject *
_elementtree_Element___copy___impl(ElementObject *self); _elementtree_Element___copy___impl(ElementObject *self, PyTypeObject *cls);
static PyObject * static PyObject *
_elementtree_Element___copy__(ElementObject *self, PyObject *Py_UNUSED(ignored)) _elementtree_Element___copy__(ElementObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{ {
return _elementtree_Element___copy___impl(self); if (nargs) {
PyErr_SetString(PyExc_TypeError, "__copy__() takes no arguments");
return NULL;
}
return _elementtree_Element___copy___impl(self, cls);
} }
PyDoc_STRVAR(_elementtree_Element___deepcopy____doc__, PyDoc_STRVAR(_elementtree_Element___deepcopy____doc__,
@ -148,7 +171,42 @@ PyDoc_STRVAR(_elementtree_Element___setstate____doc__,
"\n"); "\n");
#define _ELEMENTTREE_ELEMENT___SETSTATE___METHODDEF \ #define _ELEMENTTREE_ELEMENT___SETSTATE___METHODDEF \
{"__setstate__", (PyCFunction)_elementtree_Element___setstate__, METH_O, _elementtree_Element___setstate____doc__}, {"__setstate__", _PyCFunction_CAST(_elementtree_Element___setstate__), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _elementtree_Element___setstate____doc__},
static PyObject *
_elementtree_Element___setstate___impl(ElementObject *self,
PyTypeObject *cls, PyObject *state);
static PyObject *
_elementtree_Element___setstate__(ElementObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
PyObject *return_value = NULL;
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
# define KWTUPLE (PyObject *)&_Py_SINGLETON(tuple_empty)
#else
# define KWTUPLE NULL
#endif
static const char * const _keywords[] = {"", NULL};
static _PyArg_Parser _parser = {
.keywords = _keywords,
.fname = "__setstate__",
.kwtuple = KWTUPLE,
};
#undef KWTUPLE
PyObject *argsbuf[1];
PyObject *state;
args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
if (!args) {
goto exit;
}
state = args[0];
return_value = _elementtree_Element___setstate___impl(self, cls, state);
exit:
return return_value;
}
PyDoc_STRVAR(_elementtree_Element_extend__doc__, PyDoc_STRVAR(_elementtree_Element_extend__doc__,
"extend($self, elements, /)\n" "extend($self, elements, /)\n"
@ -156,7 +214,42 @@ PyDoc_STRVAR(_elementtree_Element_extend__doc__,
"\n"); "\n");
#define _ELEMENTTREE_ELEMENT_EXTEND_METHODDEF \ #define _ELEMENTTREE_ELEMENT_EXTEND_METHODDEF \
{"extend", (PyCFunction)_elementtree_Element_extend, METH_O, _elementtree_Element_extend__doc__}, {"extend", _PyCFunction_CAST(_elementtree_Element_extend), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _elementtree_Element_extend__doc__},
static PyObject *
_elementtree_Element_extend_impl(ElementObject *self, PyTypeObject *cls,
PyObject *elements);
static PyObject *
_elementtree_Element_extend(ElementObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
PyObject *return_value = NULL;
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
# define KWTUPLE (PyObject *)&_Py_SINGLETON(tuple_empty)
#else
# define KWTUPLE NULL
#endif
static const char * const _keywords[] = {"", NULL};
static _PyArg_Parser _parser = {
.keywords = _keywords,
.fname = "extend",
.kwtuple = KWTUPLE,
};
#undef KWTUPLE
PyObject *argsbuf[1];
PyObject *elements;
args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
if (!args) {
goto exit;
}
elements = args[0];
return_value = _elementtree_Element_extend_impl(self, cls, elements);
exit:
return return_value;
}
PyDoc_STRVAR(_elementtree_Element_find__doc__, PyDoc_STRVAR(_elementtree_Element_find__doc__,
"find($self, /, path, namespaces=None)\n" "find($self, /, path, namespaces=None)\n"
@ -164,14 +257,14 @@ PyDoc_STRVAR(_elementtree_Element_find__doc__,
"\n"); "\n");
#define _ELEMENTTREE_ELEMENT_FIND_METHODDEF \ #define _ELEMENTTREE_ELEMENT_FIND_METHODDEF \
{"find", _PyCFunction_CAST(_elementtree_Element_find), METH_FASTCALL|METH_KEYWORDS, _elementtree_Element_find__doc__}, {"find", _PyCFunction_CAST(_elementtree_Element_find), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _elementtree_Element_find__doc__},
static PyObject * static PyObject *
_elementtree_Element_find_impl(ElementObject *self, PyObject *path, _elementtree_Element_find_impl(ElementObject *self, PyTypeObject *cls,
PyObject *namespaces); PyObject *path, PyObject *namespaces);
static PyObject * static PyObject *
_elementtree_Element_find(ElementObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) _elementtree_Element_find(ElementObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{ {
PyObject *return_value = NULL; PyObject *return_value = NULL;
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
@ -214,7 +307,7 @@ _elementtree_Element_find(ElementObject *self, PyObject *const *args, Py_ssize_t
} }
namespaces = args[1]; namespaces = args[1];
skip_optional_pos: skip_optional_pos:
return_value = _elementtree_Element_find_impl(self, path, namespaces); return_value = _elementtree_Element_find_impl(self, cls, path, namespaces);
exit: exit:
return return_value; return return_value;
@ -226,15 +319,15 @@ PyDoc_STRVAR(_elementtree_Element_findtext__doc__,
"\n"); "\n");
#define _ELEMENTTREE_ELEMENT_FINDTEXT_METHODDEF \ #define _ELEMENTTREE_ELEMENT_FINDTEXT_METHODDEF \
{"findtext", _PyCFunction_CAST(_elementtree_Element_findtext), METH_FASTCALL|METH_KEYWORDS, _elementtree_Element_findtext__doc__}, {"findtext", _PyCFunction_CAST(_elementtree_Element_findtext), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _elementtree_Element_findtext__doc__},
static PyObject * static PyObject *
_elementtree_Element_findtext_impl(ElementObject *self, PyObject *path, _elementtree_Element_findtext_impl(ElementObject *self, PyTypeObject *cls,
PyObject *default_value, PyObject *path, PyObject *default_value,
PyObject *namespaces); PyObject *namespaces);
static PyObject * static PyObject *
_elementtree_Element_findtext(ElementObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) _elementtree_Element_findtext(ElementObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{ {
PyObject *return_value = NULL; PyObject *return_value = NULL;
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
@ -284,7 +377,7 @@ _elementtree_Element_findtext(ElementObject *self, PyObject *const *args, Py_ssi
} }
namespaces = args[2]; namespaces = args[2];
skip_optional_pos: skip_optional_pos:
return_value = _elementtree_Element_findtext_impl(self, path, default_value, namespaces); return_value = _elementtree_Element_findtext_impl(self, cls, path, default_value, namespaces);
exit: exit:
return return_value; return return_value;
@ -296,14 +389,14 @@ PyDoc_STRVAR(_elementtree_Element_findall__doc__,
"\n"); "\n");
#define _ELEMENTTREE_ELEMENT_FINDALL_METHODDEF \ #define _ELEMENTTREE_ELEMENT_FINDALL_METHODDEF \
{"findall", _PyCFunction_CAST(_elementtree_Element_findall), METH_FASTCALL|METH_KEYWORDS, _elementtree_Element_findall__doc__}, {"findall", _PyCFunction_CAST(_elementtree_Element_findall), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _elementtree_Element_findall__doc__},
static PyObject * static PyObject *
_elementtree_Element_findall_impl(ElementObject *self, PyObject *path, _elementtree_Element_findall_impl(ElementObject *self, PyTypeObject *cls,
PyObject *namespaces); PyObject *path, PyObject *namespaces);
static PyObject * static PyObject *
_elementtree_Element_findall(ElementObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) _elementtree_Element_findall(ElementObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{ {
PyObject *return_value = NULL; PyObject *return_value = NULL;
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
@ -346,7 +439,7 @@ _elementtree_Element_findall(ElementObject *self, PyObject *const *args, Py_ssiz
} }
namespaces = args[1]; namespaces = args[1];
skip_optional_pos: skip_optional_pos:
return_value = _elementtree_Element_findall_impl(self, path, namespaces); return_value = _elementtree_Element_findall_impl(self, cls, path, namespaces);
exit: exit:
return return_value; return return_value;
@ -358,14 +451,14 @@ PyDoc_STRVAR(_elementtree_Element_iterfind__doc__,
"\n"); "\n");
#define _ELEMENTTREE_ELEMENT_ITERFIND_METHODDEF \ #define _ELEMENTTREE_ELEMENT_ITERFIND_METHODDEF \
{"iterfind", _PyCFunction_CAST(_elementtree_Element_iterfind), METH_FASTCALL|METH_KEYWORDS, _elementtree_Element_iterfind__doc__}, {"iterfind", _PyCFunction_CAST(_elementtree_Element_iterfind), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _elementtree_Element_iterfind__doc__},
static PyObject * static PyObject *
_elementtree_Element_iterfind_impl(ElementObject *self, PyObject *path, _elementtree_Element_iterfind_impl(ElementObject *self, PyTypeObject *cls,
PyObject *namespaces); PyObject *path, PyObject *namespaces);
static PyObject * static PyObject *
_elementtree_Element_iterfind(ElementObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) _elementtree_Element_iterfind(ElementObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{ {
PyObject *return_value = NULL; PyObject *return_value = NULL;
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
@ -408,7 +501,7 @@ _elementtree_Element_iterfind(ElementObject *self, PyObject *const *args, Py_ssi
} }
namespaces = args[1]; namespaces = args[1];
skip_optional_pos: skip_optional_pos:
return_value = _elementtree_Element_iterfind_impl(self, path, namespaces); return_value = _elementtree_Element_iterfind_impl(self, cls, path, namespaces);
exit: exit:
return return_value; return return_value;
@ -482,13 +575,14 @@ PyDoc_STRVAR(_elementtree_Element_iter__doc__,
"\n"); "\n");
#define _ELEMENTTREE_ELEMENT_ITER_METHODDEF \ #define _ELEMENTTREE_ELEMENT_ITER_METHODDEF \
{"iter", _PyCFunction_CAST(_elementtree_Element_iter), METH_FASTCALL|METH_KEYWORDS, _elementtree_Element_iter__doc__}, {"iter", _PyCFunction_CAST(_elementtree_Element_iter), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _elementtree_Element_iter__doc__},
static PyObject * static PyObject *
_elementtree_Element_iter_impl(ElementObject *self, PyObject *tag); _elementtree_Element_iter_impl(ElementObject *self, PyTypeObject *cls,
PyObject *tag);
static PyObject * static PyObject *
_elementtree_Element_iter(ElementObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) _elementtree_Element_iter(ElementObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{ {
PyObject *return_value = NULL; PyObject *return_value = NULL;
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
@ -529,7 +623,7 @@ _elementtree_Element_iter(ElementObject *self, PyObject *const *args, Py_ssize_t
} }
tag = args[0]; tag = args[0];
skip_optional_pos: skip_optional_pos:
return_value = _elementtree_Element_iter_impl(self, tag); return_value = _elementtree_Element_iter_impl(self, cls, tag);
exit: exit:
return return_value; return return_value;
@ -541,15 +635,19 @@ PyDoc_STRVAR(_elementtree_Element_itertext__doc__,
"\n"); "\n");
#define _ELEMENTTREE_ELEMENT_ITERTEXT_METHODDEF \ #define _ELEMENTTREE_ELEMENT_ITERTEXT_METHODDEF \
{"itertext", (PyCFunction)_elementtree_Element_itertext, METH_NOARGS, _elementtree_Element_itertext__doc__}, {"itertext", _PyCFunction_CAST(_elementtree_Element_itertext), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _elementtree_Element_itertext__doc__},
static PyObject * static PyObject *
_elementtree_Element_itertext_impl(ElementObject *self); _elementtree_Element_itertext_impl(ElementObject *self, PyTypeObject *cls);
static PyObject * static PyObject *
_elementtree_Element_itertext(ElementObject *self, PyObject *Py_UNUSED(ignored)) _elementtree_Element_itertext(ElementObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{ {
return _elementtree_Element_itertext_impl(self); if (nargs) {
PyErr_SetString(PyExc_TypeError, "itertext() takes no arguments");
return NULL;
}
return _elementtree_Element_itertext_impl(self, cls);
} }
PyDoc_STRVAR(_elementtree_Element_insert__doc__, PyDoc_STRVAR(_elementtree_Element_insert__doc__,
@ -637,20 +735,35 @@ PyDoc_STRVAR(_elementtree_Element_makeelement__doc__,
"\n"); "\n");
#define _ELEMENTTREE_ELEMENT_MAKEELEMENT_METHODDEF \ #define _ELEMENTTREE_ELEMENT_MAKEELEMENT_METHODDEF \
{"makeelement", _PyCFunction_CAST(_elementtree_Element_makeelement), METH_FASTCALL, _elementtree_Element_makeelement__doc__}, {"makeelement", _PyCFunction_CAST(_elementtree_Element_makeelement), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _elementtree_Element_makeelement__doc__},
static PyObject * static PyObject *
_elementtree_Element_makeelement_impl(ElementObject *self, PyObject *tag, _elementtree_Element_makeelement_impl(ElementObject *self, PyTypeObject *cls,
PyObject *attrib); PyObject *tag, PyObject *attrib);
static PyObject * static PyObject *
_elementtree_Element_makeelement(ElementObject *self, PyObject *const *args, Py_ssize_t nargs) _elementtree_Element_makeelement(ElementObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{ {
PyObject *return_value = NULL; PyObject *return_value = NULL;
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
# define KWTUPLE (PyObject *)&_Py_SINGLETON(tuple_empty)
#else
# define KWTUPLE NULL
#endif
static const char * const _keywords[] = {"", "", NULL};
static _PyArg_Parser _parser = {
.keywords = _keywords,
.fname = "makeelement",
.kwtuple = KWTUPLE,
};
#undef KWTUPLE
PyObject *argsbuf[2];
PyObject *tag; PyObject *tag;
PyObject *attrib; PyObject *attrib;
if (!_PyArg_CheckPositional("makeelement", nargs, 2, 2)) { args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 2, 0, argsbuf);
if (!args) {
goto exit; goto exit;
} }
tag = args[0]; tag = args[0];
@ -659,7 +772,7 @@ _elementtree_Element_makeelement(ElementObject *self, PyObject *const *args, Py_
goto exit; goto exit;
} }
attrib = args[1]; attrib = args[1];
return_value = _elementtree_Element_makeelement_impl(self, tag, attrib); return_value = _elementtree_Element_makeelement_impl(self, cls, tag, attrib);
exit: exit:
return return_value; return return_value;
@ -1105,4 +1218,4 @@ skip_optional:
exit: exit:
return return_value; return return_value;
} }
/*[clinic end generated code: output=d380adb43d8f4a62 input=a9049054013a1b77]*/ /*[clinic end generated code: output=40767b1a98e54b60 input=a9049054013a1b77]*/