diff options
author | Andrew Bartlett <abartlet@samba.org> | 2009-08-24 20:11:43 +1000 |
---|---|---|
committer | Andrew Bartlett <abartlet@samba.org> | 2009-08-24 20:24:18 +1000 |
commit | 7234a24f821743c60075d1e2868fba7b0f2a8f8b (patch) | |
tree | d73a9a316577a4af32e04908ce04fbfccd529919 /source4/lib | |
parent | b4e8d927cd91b2fc1221d9834715153c7487b715 (diff) | |
download | samba-7234a24f821743c60075d1e2868fba7b0f2a8f8b.tar.gz samba-7234a24f821743c60075d1e2868fba7b0f2a8f8b.tar.bz2 samba-7234a24f821743c60075d1e2868fba7b0f2a8f8b.zip |
s4:ldb Add python binding and test for ldb_msg_diff()
Diffstat (limited to 'source4/lib')
-rw-r--r-- | source4/lib/ldb/pyldb.c | 32 | ||||
-rwxr-xr-x | source4/lib/ldb/tests/python/api.py | 11 |
2 files changed, 43 insertions, 0 deletions
diff --git a/source4/lib/ldb/pyldb.c b/source4/lib/ldb/pyldb.c index d55e0aae7c..67e1d5c9e0 100644 --- a/source4/lib/ldb/pyldb.c +++ b/source4/lib/ldb/pyldb.c @@ -845,6 +845,35 @@ static PyObject *py_ldb_parse_ldif(PyLdbObject *self, PyObject *args) return PyObject_GetIter(list); } +static PyObject *py_ldb_msg_diff(PyLdbObject *self, PyObject *args) +{ + PyObject *py_msg_old; + PyObject *py_msg_new; + struct ldb_message *diff; + PyObject *py_ret; + + if (!PyArg_ParseTuple(args, "OO", &py_msg_old, &py_msg_new)) + return NULL; + + if (!PyLdbMessage_Check(py_msg_old)) { + PyErr_SetString(PyExc_TypeError, "Expected Ldb Message for old message"); + return NULL; + } + + if (!PyLdbMessage_Check(py_msg_new)) { + PyErr_SetString(PyExc_TypeError, "Expected Ldb Message for new message"); + return NULL; + } + + diff = ldb_msg_diff(PyLdb_AsLdbContext(self), PyLdbMessage_AsMessage(py_msg_old), PyLdbMessage_AsMessage(py_msg_new)); + if (diff == NULL) + return NULL; + + py_ret = PyLdbMessage_FromMessage(diff); + + return py_ret; +} + static PyObject *py_ldb_schema_format_value(PyLdbObject *self, PyObject *args) { const struct ldb_schema_attribute *a; @@ -1087,6 +1116,9 @@ static PyMethodDef py_ldb_methods[] = { { "parse_ldif", (PyCFunction)py_ldb_parse_ldif, METH_VARARGS, "S.parse_ldif(ldif) -> iter(messages)\n" "Parse a string formatted using LDIF." }, + { "msg_diff", (PyCFunction)py_ldb_msg_diff, METH_VARARGS, + "S.msg_diff(Message) -> Message\n" + "Return an LDB Message of the difference between two Message objects." }, { "get_opaque", (PyCFunction)py_ldb_get_opaque, METH_VARARGS, "S.get_opaque(name) -> value\n" "Get an opaque value set on this LDB connection. \n" diff --git a/source4/lib/ldb/tests/python/api.py b/source4/lib/ldb/tests/python/api.py index 110b1cabfe..d946bf06a5 100755 --- a/source4/lib/ldb/tests/python/api.py +++ b/source4/lib/ldb/tests/python/api.py @@ -451,6 +451,17 @@ class LdbMsgTests(unittest.TestCase): def test_get_unknown(self): self.assertEquals(None, self.msg.get("lalalala")) + def test_msg_diff(self): + l = ldb.Ldb() + msgs = l.parse_ldif("dn: foo=bar\nfoo: bar\nbaz: do\n\ndn: foo=bar\nfoo: bar\nbaz: dont\n") + msg1 = msgs.next()[1] + msg2 = msgs.next()[1] + msgdiff = l.msg_diff(msg1, msg2) + self.assertEquals("foo=bar", msgdiff.get("dn").__str__()) + self.assertRaises(KeyError, lambda: msgdiff["foo"]) + self.assertEquals(1, len(msgdiff)) + + class MessageElementTests(unittest.TestCase): |