diff options
Diffstat (limited to 'source4/lib')
-rw-r--r-- | source4/lib/ldb/ldb.i | 5 | ||||
-rw-r--r-- | source4/lib/ldb/ldb.py | 1 | ||||
-rw-r--r-- | source4/lib/ldb/ldb_wrap.c | 27 | ||||
-rwxr-xr-x | source4/lib/ldb/tests/python/api.py | 4 |
4 files changed, 37 insertions, 0 deletions
diff --git a/source4/lib/ldb/ldb.i b/source4/lib/ldb/ldb.i index 0ad628fdf5..57fa36584e 100644 --- a/source4/lib/ldb/ldb.i +++ b/source4/lib/ldb/ldb.i @@ -278,6 +278,11 @@ typedef struct ldb_message_element { { return ldb_msg_element_from_pyobject(NULL, set_obj, flags, name); } + + int __len__() + { + return $self->num_values; + } #endif PyObject *get(int i) diff --git a/source4/lib/ldb/ldb.py b/source4/lib/ldb/ldb.py index 51a4a0fadb..2d037f080c 100644 --- a/source4/lib/ldb/ldb.py +++ b/source4/lib/ldb/ldb.py @@ -110,6 +110,7 @@ class ldb_msg_element(object): ldb_msg_element.__iter__ = new_instancemethod(_ldb.ldb_msg_element___iter__,None,ldb_msg_element) ldb_msg_element.__set__ = new_instancemethod(_ldb.ldb_msg_element___set__,None,ldb_msg_element) +ldb_msg_element.__len__ = new_instancemethod(_ldb.ldb_msg_element___len__,None,ldb_msg_element) ldb_msg_element.get = new_instancemethod(_ldb.ldb_msg_element_get,None,ldb_msg_element) ldb_msg_element.__cmp__ = new_instancemethod(_ldb.ldb_msg_element___cmp__,None,ldb_msg_element) ldb_msg_element_swigregister = _ldb.ldb_msg_element_swigregister diff --git a/source4/lib/ldb/ldb_wrap.c b/source4/lib/ldb/ldb_wrap.c index 6e809b6504..10ea4f4a24 100644 --- a/source4/lib/ldb/ldb_wrap.c +++ b/source4/lib/ldb/ldb_wrap.c @@ -2889,6 +2889,9 @@ SWIG_AsVal_int (PyObject * obj, int *val) SWIGINTERN ldb_msg_element *new_ldb_msg_element(PyObject *set_obj,int flags,char const *name){ return ldb_msg_element_from_pyobject(NULL, set_obj, flags, name); } +SWIGINTERN int ldb_msg_element___len__(ldb_msg_element *self){ + return self->num_values; + } SWIGINTERN PyObject *ldb_msg_element_get(ldb_msg_element *self,int i){ if (i < 0 || i >= self->num_values) return Py_None; @@ -3679,6 +3682,29 @@ fail: } +SWIGINTERN PyObject *_wrap_ldb_msg_element___len__(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { + PyObject *resultobj = 0; + ldb_msg_element *arg1 = (ldb_msg_element *) 0 ; + int result; + void *argp1 = 0 ; + int res1 = 0 ; + PyObject *swig_obj[1] ; + + if (!args) SWIG_fail; + swig_obj[0] = args; + res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_ldb_message_element, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "ldb_msg_element___len__" "', argument " "1"" of type '" "ldb_msg_element *""'"); + } + arg1 = (ldb_msg_element *)(argp1); + result = (int)ldb_msg_element___len__(arg1); + resultobj = SWIG_From_int((int)(result)); + return resultobj; +fail: + return NULL; +} + + SWIGINTERN PyObject *_wrap_ldb_msg_element_get(PyObject *SWIGUNUSEDPARM(self), PyObject *args, PyObject *kwargs) { PyObject *resultobj = 0; ldb_msg_element *arg1 = (ldb_msg_element *) 0 ; @@ -5296,6 +5322,7 @@ static PyMethodDef SwigMethods[] = { { (char *)"ldb_msg_element___iter__", (PyCFunction)_wrap_ldb_msg_element___iter__, METH_O, NULL}, { (char *)"ldb_msg_element___set__", (PyCFunction)_wrap_ldb_msg_element___set__, METH_O, NULL}, { (char *)"new_MessageElement", (PyCFunction) _wrap_new_MessageElement, METH_VARARGS | METH_KEYWORDS, NULL}, + { (char *)"ldb_msg_element___len__", (PyCFunction)_wrap_ldb_msg_element___len__, METH_O, NULL}, { (char *)"ldb_msg_element_get", (PyCFunction) _wrap_ldb_msg_element_get, METH_VARARGS | METH_KEYWORDS, NULL}, { (char *)"delete_ldb_msg_element", (PyCFunction)_wrap_delete_ldb_msg_element, METH_O, NULL}, { (char *)"ldb_msg_element___cmp__", (PyCFunction) _wrap_ldb_msg_element___cmp__, METH_VARARGS | METH_KEYWORDS, NULL}, diff --git a/source4/lib/ldb/tests/python/api.py b/source4/lib/ldb/tests/python/api.py index 0a5ba035ff..5ab40106a8 100755 --- a/source4/lib/ldb/tests/python/api.py +++ b/source4/lib/ldb/tests/python/api.py @@ -388,6 +388,10 @@ class MessageElementTests(unittest.TestCase): self.assertEquals("bar", x[1]) self.assertRaises(KeyError, lambda: x[-1]) + def test_len(self): + x = ldb.MessageElement(["foo", "bar"]) + self.assertEquals(2, len(x)) + class ExampleModule: name = "example" |