summaryrefslogtreecommitdiff
path: root/source4/lib/ldb
diff options
context:
space:
mode:
authorJelmer Vernooij <jelmer@samba.org>2008-01-11 01:02:58 +0100
committerJelmer Vernooij <jelmer@samba.org>2008-01-11 01:04:25 +0100
commitc3695026e1cfac3e835e937ed9343d82500cf197 (patch)
tree1e3bcbfb58bd300340e044a9879a09ada5925af6 /source4/lib/ldb
parent9269db983d847be7a0cdc9eb2bcc4ebe3066be1c (diff)
downloadsamba-c3695026e1cfac3e835e937ed9343d82500cf197.tar.gz
samba-c3695026e1cfac3e835e937ed9343d82500cf197.tar.bz2
samba-c3695026e1cfac3e835e937ed9343d82500cf197.zip
ldb/python: Implement __len__ for MessageElement.
(This used to be commit a8f90ed34ce9341080b63c801ef54b82de42b8e6)
Diffstat (limited to 'source4/lib/ldb')
-rw-r--r--source4/lib/ldb/ldb.i5
-rw-r--r--source4/lib/ldb/ldb.py1
-rw-r--r--source4/lib/ldb/ldb_wrap.c27
-rwxr-xr-xsource4/lib/ldb/tests/python/api.py4
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"