pyldb: Add bindings for ldb_dn_remove_base_components
authorAndrew Bartlett <abartlet@samba.org>
Fri, 6 Jul 2012 09:57:10 +0000 (19:57 +1000)
committerAndrew Bartlett <abartlet@samba.org>
Fri, 6 Jul 2012 12:55:49 +0000 (22:55 +1000)
lib/ldb/pyldb.c
lib/ldb/tests/python/api.py

index 9c8a70b5292401823288be969fbef71cc0d3b8c5..8c9d6b9599bacd510119fa6dbdd8d0d412f3a172 100644 (file)
@@ -529,6 +529,18 @@ static PyObject *py_ldb_dn_add_base(PyLdbDnObject *self, PyObject *args)
        return ldb_dn_add_base(dn, other)?Py_True:Py_False;
 }
 
+static PyObject *py_ldb_dn_remove_base_components(PyLdbDnObject *self, PyObject *args)
+{
+       struct ldb_dn *dn;
+       int i;
+       if (!PyArg_ParseTuple(args, "i", &i))
+               return NULL;
+
+       dn = pyldb_Dn_AsDn((PyObject *)self);
+
+       return ldb_dn_remove_base_components(dn, i)?Py_True:Py_False;
+}
+
 static PyObject *py_ldb_dn_is_child_of(PyLdbDnObject *self, PyObject *args)
 {
        PyObject *py_base;
@@ -579,6 +591,9 @@ static PyMethodDef py_ldb_dn_methods[] = {
        { "add_base", (PyCFunction)py_ldb_dn_add_base, METH_VARARGS,
                "S.add_base(dn) -> None\n"
                "Add a base DN to this DN." },
+       { "remove_base_components", (PyCFunction)py_ldb_dn_remove_base_components, METH_VARARGS,
+               "S.remove_base_components(int) -> bool\n"
+               "Remove a number of DN components from the base of this DN." },
        { "check_special", (PyCFunction)py_ldb_dn_check_special, METH_VARARGS,
                "S.check_special(name) -> bool\n\n"
                "Check if name is a special DN name"},
index d04d0cc5ed636d3f8a37b2b9d3d99e64b7b1308e..7df40e4a5a85294445a49674da378157ae42339d 100755 (executable)
@@ -416,6 +416,11 @@ class DnTests(TestCase):
         y = ldb.Dn(self.ldb, "bar=bla")
         self.assertEquals("dc=foo24,bar=bla", str(x + y))
 
+    def test_remove_base_components(self):
+        x = ldb.Dn(self.ldb, "dc=foo24,dc=samba,dc=org")
+        x.remove_base_components(len(x)-1)
+        self.assertEquals("dc=foo24", str(x))
+
     def test_parse_ldif(self):
         msgs = self.ldb.parse_ldif("dn: foo=bar\n")
         msg = msgs.next()