From bd41ecdcd0b566c63b9c184a8f5ffdf8db8bd869 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Sat, 15 Apr 2006 10:10:23 +0000 Subject: r15091: Raise LdbError instead of IOError when ldb function calls return an error. (This used to be commit e13c6d7c49e1586cc9b25c30d3f9d51f42d1c785) --- source4/lib/ldb/swig/Ldb.py | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) (limited to 'source4/lib/ldb/swig') diff --git a/source4/lib/ldb/swig/Ldb.py b/source4/lib/ldb/swig/Ldb.py index f761aec398..00480ca3e8 100644 --- a/source4/lib/ldb/swig/Ldb.py +++ b/source4/lib/ldb/swig/Ldb.py @@ -22,6 +22,10 @@ import ldb +class LdbError(Exception): + """An exception raised when a ldb error occurs.""" + pass + class LdbElement: """A class representing a ldb element as an array of values.""" @@ -84,19 +88,22 @@ class Ldb: def search(self, expression): - result = ldb.search(self.ldb_ctx, None, ldb.LDB_SCOPE_DEFAULT, - expression, None); + self._ldb_call(ldb.search, self.ldb_ctx, None, ldb.LDB_SCOPE_DEFAULT, + expression, None); return [LdbMessage(ldb.ldb_message_ptr_array_getitem(result.msgs, ndx)) for ndx in range(result.count)] + def _ldb_call(self, fn, *args): + result = fn(*args) + if result != ldb.LDB_SUCCESS: + raise LdbError, (result, ldb.strerror(result)) + def delete(self, dn): - if ldb.delete(self.ldb_ctx, dn) != 0: - raise IOError, ldb.errstring(self.ldb_ctx) + self._ldb_call(ldb.delete, self.ldb_ctx, dn) def rename(self, olddn, newdn): - if ldb.rename(self.ldb_ctx, olddn, newdn) != 0: - raise IOError, ldb.errstring(self.ldb_ctx) + self._ldb_call(ldb.rename, self.ldb_ctx, olddn, newdn) def add(self, msg): - ldb.add(self.ldb_ctx, msg) + self._ldb_call(ldb.add, self.ldb_ctx, msg) -- cgit