svn commit: samba r26043 - in branches/4.0-python: . source/lib/ldb
source/lib/ldb/tests/python source/scripting/python/samba
jelmer at samba.org
jelmer at samba.org
Mon Nov 19 19:57:44 GMT 2007
Author: jelmer
Date: 2007-11-19 19:57:43 +0000 (Mon, 19 Nov 2007)
New Revision: 26043
WebSVN: http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=26043
Log:
Add specific ldb exception class.
Modified:
branches/4.0-python/
branches/4.0-python/source/lib/ldb/ldb.i
branches/4.0-python/source/lib/ldb/tests/python/api.py
branches/4.0-python/source/scripting/python/samba/provision.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/ldb.i
===================================================================
--- branches/4.0-python/source/lib/ldb/ldb.i 2007-11-19 19:28:24 UTC (rev 26042)
+++ branches/4.0-python/source/lib/ldb/ldb.i 2007-11-19 19:57:43 UTC (rev 26043)
@@ -428,6 +428,23 @@
}
/*
+ * Wrap ldb errors
+ */
+
+%{
+PyObject *PyExc_LdbError;
+%}
+
+%pythoncode %{
+ LdbError = _ldb.LdbError
+%}
+
+%init %{
+ PyExc_LdbError = PyErr_NewException("_ldb.LdbError", NULL, NULL);
+ PyDict_SetItemString(d, "LdbError", PyExc_LdbError);
+%}
+
+/*
* Wrap ldb functions
*/
@@ -435,8 +452,10 @@
/* Top-level ldb operations */
typedef struct ldb_context {
%typemap(out) ldb_error {
- if ($1 != LDB_SUCCESS)
- SWIG_exception(SWIG_RuntimeError, ldb_strerror($1));
+ if ($1 != LDB_SUCCESS) {
+ PyErr_SetObject(PyExc_LdbError, Py_BuildValue("(i,s)", $1, ldb_strerror($1)));
+ SWIG_fail;
+ }
$result = Py_None;
};
%extend {
Modified: branches/4.0-python/source/lib/ldb/tests/python/api.py
===================================================================
--- branches/4.0-python/source/lib/ldb/tests/python/api.py 2007-11-19 19:28:24 UTC (rev 26042)
+++ branches/4.0-python/source/lib/ldb/tests/python/api.py 2007-11-19 19:57:43 UTC (rev 26043)
@@ -56,7 +56,7 @@
def test_delete(self):
l = ldb.Ldb("foo.tdb")
- self.assertRaises(RuntimeError, lambda: l.delete(ldb.Dn(l, "dc=foo")))
+ self.assertRaises(ldb.LdbError, lambda: l.delete(ldb.Dn(l, "dc=foo")))
def test_contains(self):
l = ldb.Ldb("foo.tdb")
Modified: branches/4.0-python/source/scripting/python/samba/provision.py
===================================================================
--- branches/4.0-python/source/scripting/python/samba/provision.py 2007-11-19 19:28:24 UTC (rev 26042)
+++ branches/4.0-python/source/scripting/python/samba/provision.py 2007-11-19 19:57:43 UTC (rev 26043)
@@ -14,7 +14,7 @@
import param
import registry
from samba import Ldb, substitute_var
-from ldb import Dn, SCOPE_SUBTREE, SCOPE_ONELEVEL, SCOPE_BASE
+from ldb import Dn, SCOPE_SUBTREE, SCOPE_ONELEVEL, SCOPE_BASE, LdbError
class InvalidNetbiosName(Exception):
@@ -206,7 +206,7 @@
"@OPTIONS", "@PARTITION", "@KLUDGEACL"]:
try:
ldb.delete(Dn(ldb, attr))
- except RuntimeError:
+ except LdbError:
# Ignore missing dn errors
pass
@@ -217,12 +217,12 @@
"(&(|(objectclass=*)(dn=*))(!(dn=@BASEINFO)))",
["dn"]):
ldb.delete(msg.dn)
- except RuntimeError:
+ except LdbError:
ldb_delete(ldb)
try:
res = ldb.search(basedn, SCOPE_SUBTREE, "(&(|(objectclass=*)(dn=*))(!(dn=@BASEINFO)))", ["dn"])
- except RuntimeError:
+ except LdbError:
ldb_delete(ldb)
return
assert len(res) == 0
@@ -271,7 +271,7 @@
def open_ldb(session_info, credentials, dbname):
try:
return Ldb(dbname, session_info=session_info, credentials=credentials)
- except RuntimeError, e:
+ except LdbError:
os.unlink(dbname)
return Ldb(dbname, session_info=session_info, credentials=credentials)
@@ -288,7 +288,7 @@
for msg in ldb.parse_ldif(data):
try:
ldb.add(msg[1])
- except:
+ except LdbError, e:
import pdb
pdb.set_trace()
raise
More information about the samba-cvs
mailing list