svn commit: samba r25946 - in branches/4.0-python: .
source/lib/ldb/swig source/lib/ldb/tests/python
jelmer at samba.org
jelmer at samba.org
Wed Nov 14 02:46:11 GMT 2007
Author: jelmer
Date: 2007-11-14 02:46:10 +0000 (Wed, 14 Nov 2007)
New Revision: 25946
WebSVN: http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=25946
Log:
Add ability to use dictionary as argument to Ldb.add.
Modified:
branches/4.0-python/
branches/4.0-python/source/lib/ldb/swig/ldb.i
branches/4.0-python/source/lib/ldb/tests/python/api.py
Changeset:
Property changes on: branches/4.0-python
___________________________________________________________________
Name: bzr:revision-info
...skipped...
Name: bzr:file-ids
...skipped...
Name: bzr:revision-id:v3-trunk0
...skipped...
Modified: branches/4.0-python/source/lib/ldb/swig/ldb.i
===================================================================
--- branches/4.0-python/source/lib/ldb/swig/ldb.i 2007-11-14 01:07:39 UTC (rev 25945)
+++ branches/4.0-python/source/lib/ldb/swig/ldb.i 2007-11-14 02:46:10 UTC (rev 25946)
@@ -106,6 +106,38 @@
$result = PyString_FromStringAndSize((const char *)$1.data, $1.length);
}
+%typemap(in) ldb_msg *add_msg (int dict_pos, int msg_pos, PyObject *key, PyObject *value,
+ ldb_msg_element *msgel) {
+ if (PyDict_Check($input)) {
+ $1 = ldb_msg_new(NULL);
+ $1->num_elements = PyDict_Size($input) - 1; /* dn isn't in there */
+ $1->elements = talloc_zero_array($1, struct ldb_message_element, $1->num_elements);
+ msg_pos = dict_pos = 0;
+ while (PyDict_Next($input, &dict_pos, &key, &value)) {
+ if (!strcmp(PyString_AsString(key), "dn")) {
+ if (ldb_dn_from_pyobject(value, &$1->dn) != 0)
+ SWIG_exception(SWIG_TypeError, "unable to convert dn");
+ } else {
+ msgel = ldb_msg_element_from_pyobject(value, 0, PyString_AsString(key));
+ memcpy(&$1->elements[msg_pos], msgel, sizeof(*msgel));
+ msg_pos++;
+ }
+ dict_pos++;
+ }
+
+ if ($1->dn == NULL)
+ SWIG_exception(SWIG_TypeError, "no dn set");
+ } else {
+ if (SWIG_ConvertPtr($input, &$1, SWIGTYPE_p_ldb_message, 0) != 0)
+ return NULL;
+ }
+}
+
+%typemap(freearg) ldb_msg *add_msg {
+//talloc_free($1);
+}
+
+
/*
* Wrap struct ldb_result
*/
@@ -202,6 +234,11 @@
#ifdef SWIGPYTHON
%inline {
+int ldb_dn_from_pyobject(PyObject *object, ldb_dn **dn)
+{
+ return SWIG_ConvertPtr(object, dn, SWIGTYPE_p_ldb_dn, 0);
+}
+
ldb_msg_element *ldb_msg_element_from_pyobject(PyObject *set_obj, int flags,
const char *attr_name)
{
@@ -291,6 +328,7 @@
%rename(__getitem__) ldb_message::find_element;
//%typemap(out) ldb_msg_element *;
+
%inline {
PyObject *ldb_msg_list_elements(ldb_msg *msg)
{
@@ -414,7 +452,7 @@
struct ldb_result **OUT);
ldb_error delete(ldb_dn *dn);
ldb_error rename(ldb_dn *olddn, ldb_dn *newdn);
- ldb_error add(ldb_msg *message);
+ ldb_error add(ldb_msg *add_msg);
ldb_error modify(ldb_msg *message);
ldb_dn *get_config_basedn();
ldb_dn *get_root_basedn();
@@ -449,6 +487,7 @@
}
return PyObject_GetIter(list);
}
+
#endif
}
} ldb;
Modified: branches/4.0-python/source/lib/ldb/tests/python/api.py
===================================================================
--- branches/4.0-python/source/lib/ldb/tests/python/api.py 2007-11-14 01:07:39 UTC (rev 25945)
+++ branches/4.0-python/source/lib/ldb/tests/python/api.py 2007-11-14 02:46:10 UTC (rev 25946)
@@ -90,6 +90,17 @@
finally:
l.delete(ldb.Dn(l, "dc=foo"))
+ def test_add_dict(self):
+ l = ldb.Ldb("foo.tdb")
+ m = {"dn": ldb.Dn(l, "dc=foo"),
+ "bla": "bla"}
+ self.assertEquals(len(l.search()), 1)
+ l.add(m)
+ try:
+ self.assertEquals(len(l.search()), 2)
+ finally:
+ l.delete(ldb.Dn(l, "dc=foo"))
+
def test_rename(self):
l = ldb.Ldb("foo.tdb")
m = ldb.Message()
More information about the samba-cvs
mailing list