Author: jelmer Date: 2007-10-14 20:50:17 +0000 (Sun, 14 Oct 2007) New Revision: 25638
WebSVN: http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=25638 Log: Convert return codes to exceptions. 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: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-10-14 18:57:47 UTC (rev 25637) +++ branches/4.0-python/source/lib/ldb/swig/ldb.i 2007-10-14 20:50:17 UTC (rev 25638) @@ -45,6 +45,7 @@ typedef struct ldb_message ldb_msg; typedef struct ldb_context ldb; typedef struct ldb_dn ldb_dn; +typedef int ldb_error; %} @@ -70,6 +71,7 @@ "ldb context must be non-NULL"); } + /* * Wrap a small bit of talloc */ @@ -249,6 +251,11 @@ %rename(Ldb) ldb; /* Top-level ldb operations */ typedef struct ldb_context { + %typemap(out) ldb_error { + if ($1 != LDB_SUCCESS) + SWIG_exception(SWIG_RuntimeError, ldb_strerror($1)); + $result = Py_None; + }; %extend { ldb(const char *url=NULL, unsigned int flags = 0, const char *options[] = NULL) @@ -270,18 +277,18 @@ return NULL; } - int connect(const char *url, unsigned int flags = 0, + ldb_error connect(const char *url, unsigned int flags = 0, const char *options[] = NULL); ~ldb() { talloc_free($self); } - int search(ldb_dn *base = NULL, + ldb_error search(ldb_dn *base = NULL, enum ldb_scope scope = LDB_SCOPE_DEFAULT, const char *expression = NULL, const char * const *attrs = NULL, struct ldb_result **OUT); - int delete(ldb_dn *dn); - int rename(ldb_dn *olddn, ldb_dn *newdn); - int add(ldb_msg *message); + ldb_error delete(ldb_dn *dn); + ldb_error rename(ldb_dn *olddn, ldb_dn *newdn); + ldb_error add(ldb_msg *message); ldb_dn *get_config_basedn(); ldb_dn *get_root_basedn(); ldb_dn *get_schema_basedn(); Modified: branches/4.0-python/source/lib/ldb/tests/python/api.py =================================================================== --- branches/4.0-python/source/lib/ldb/tests/python/api.py 2007-10-14 18:57:47 UTC (rev 25637) +++ branches/4.0-python/source/lib/ldb/tests/python/api.py 2007-10-14 20:50:17 UTC (rev 25638) @@ -25,7 +25,7 @@ def test_delete(self): l = ldb.Ldb("foo.tdb") - l.delete(ldb.Dn(l, "dc=foo")) + self.assertRaises(RuntimeError, lambda: l.delete(ldb.Dn(l, "dc=foo"))) def test_get_config_basedn(self): l = ldb.Ldb("foo.tdb") @@ -43,6 +43,14 @@ l = ldb.Ldb("foo.tdb") self.assertEquals(None, l.get_default_basedn()) + def test_add(self): + l = ldb.Ldb("foo.tdb") + m = ldb.Message() + m.dn = ldb.Dn(l, "dc=foo") + m["bla"] = "bla" + self.assertEquals(len(l.search()), 1) + l.add(m) + self.assertEquals(len(l.search()), 2) class DnTests(unittest.TestCase): def setUp(self):
