self.assertEqual(flag, True)
self.assertEqual(wref(), None)
+ def test_get_keyword_args(self):
+ e1 = ET.Element('foo' , x=1, y=2, z=3)
+ self.assertEqual(e1.get('x', default=7), 1)
+ self.assertEqual(e1.get('w', default=7), 7)
+
def test_pickle(self):
# For now this test only works for the Python version of ET,
# so set sys.modules accordingly because pickle uses __import__
self.assertEqual(self._ilist(doc, 'room'), ['room'] * 3)
self.assertEqual(self._ilist(doc, 'house'), ['house'] * 2)
+ # test that iter also accepts 'tag' as a keyword arg
+ self.assertEqual(
+ summarize_list(doc.iter(tag='room')),
+ ['room'] * 3)
+
# make sure both tag=None and tag='*' return all tags
all_tags = ['document', 'house', 'room', 'room',
'shed', 'house', 'room']
}
static PyObject*
-element_get(ElementObject* self, PyObject* args)
+element_get(ElementObject* self, PyObject* args, PyObject* kwds)
{
PyObject* value;
+ static char* kwlist[] = {"key", "default", 0};
PyObject* key;
PyObject* default_value = Py_None;
- if (!PyArg_ParseTuple(args, "O|O:get", &key, &default_value))
+
+ if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|O:get", kwlist, &key,
+ &default_value))
return NULL;
if (!self->extra || self->extra->attrib == Py_None)
static PyObject *
-element_iter(ElementObject *self, PyObject *args)
+element_iter(ElementObject *self, PyObject *args, PyObject *kwds)
{
PyObject* tag = Py_None;
- if (!PyArg_ParseTuple(args, "|O:iter", &tag))
+ static char* kwlist[] = {"tag", 0};
+
+ if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O:iter", kwlist, &tag))
return NULL;
return create_elementiter(self, tag, 0);
{"clear", (PyCFunction) element_clearmethod, METH_VARARGS},
- {"get", (PyCFunction) element_get, METH_VARARGS},
+ {"get", (PyCFunction) element_get, METH_VARARGS | METH_KEYWORDS},
{"set", (PyCFunction) element_set, METH_VARARGS},
{"find", (PyCFunction) element_find, METH_VARARGS | METH_KEYWORDS},
{"insert", (PyCFunction) element_insert, METH_VARARGS},
{"remove", (PyCFunction) element_remove, METH_VARARGS},
- {"iter", (PyCFunction) element_iter, METH_VARARGS},
+ {"iter", (PyCFunction) element_iter, METH_VARARGS | METH_KEYWORDS},
{"itertext", (PyCFunction) element_itertext, METH_VARARGS},
{"iterfind", (PyCFunction) element_iterfind, METH_VARARGS | METH_KEYWORDS},
- {"getiterator", (PyCFunction) element_iter, METH_VARARGS},
+ {"getiterator", (PyCFunction) element_iter, METH_VARARGS | METH_KEYWORDS},
{"getchildren", (PyCFunction) element_getchildren, METH_VARARGS},
{"items", (PyCFunction) element_items, METH_VARARGS},
/* python module interface */
static PyMethodDef _functions[] = {
- {"SubElement", (PyCFunction) subelement, METH_VARARGS|METH_KEYWORDS},
+ {"SubElement", (PyCFunction) subelement, METH_VARARGS | METH_KEYWORDS},
{NULL, NULL}
};