summaryrefslogtreecommitdiff
path: root/source4/lib
diff options
context:
space:
mode:
authorTim Potter <tpot@samba.org>2006-04-15 10:10:23 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 14:04:08 -0500
commitbd41ecdcd0b566c63b9c184a8f5ffdf8db8bd869 (patch)
treec7662949ff5ea2d2a47fabf76a9207d65ed23b78 /source4/lib
parent6aa32f4217cfa659d042d3e6a72ec156f11b9675 (diff)
downloadsamba-bd41ecdcd0b566c63b9c184a8f5ffdf8db8bd869.tar.gz
samba-bd41ecdcd0b566c63b9c184a8f5ffdf8db8bd869.tar.bz2
samba-bd41ecdcd0b566c63b9c184a8f5ffdf8db8bd869.zip
r15091: Raise LdbError instead of IOError when ldb function calls return an
error. (This used to be commit e13c6d7c49e1586cc9b25c30d3f9d51f42d1c785)
Diffstat (limited to 'source4/lib')
-rw-r--r--source4/lib/ldb/swig/Ldb.py21
1 files changed, 14 insertions, 7 deletions
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)