ldap.schema: str2objectclass() fails

David Leonard david.leonard at itee.uq.edu.au
Sun Jul 28 13:41:04 CEST 2002


On Sun, 28 Jul 2002, Jacek Konieczny typed thusly:

> On Sat, Jul 27, 2002 at 10:38:35PM +0200, Michael Ströder wrote:
> It seems ldap_str2objectclass() fails, but no proper python-way error
> hadnling is done. The fix should be easy (just replace
> /* XXX Do error handling... */ with exception object initialization).
> Unfortunately I am not able to do it now (lack of time) :-(

is ret important?
is a subclassed error the right thing to do?

Index: schema.c
===================================================================
RCS file: /cvsroot/python-ldap/python-ldap/Modules/schema.c,v
retrieving revision 1.2
diff -u -r1.2 schema.c
--- schema.c	4 May 2002 18:14:48 -0000	1.2
+++ schema.c	28 Jul 2002 11:39:00 -0000
@@ -8,6 +8,8 @@
 #include "schema.h"
 #include "ldap_schema.h"

+static PyObject *SchemaError;
+
 /*
    This utility function takes a null delimited C array of (null
    delimited) C strings, creates its python equivalent and returns a
@@ -91,8 +93,7 @@
 	return NULL;
   o = ldap_str2objectclass( oc_string, &ret, &errp, flag);
   if (ret) {
-    printf("Error: %d: %s", ret, errp);
-    /* XXX Do error handling... */
+    PyErr_SetString(SchemaError, errp);
     return NULL;
   }

@@ -139,8 +140,7 @@
     return NULL;
   a = ldap_str2attributetype( at_string, &ret, &errp, flag);
   if (ret) {
-    printf("Error: %d: %s", ret, errp);
-    /* XXX Do error handling... */
+    PyErr_SetString(SchemaError, errp);
     return NULL;
   }

@@ -208,8 +208,7 @@
     return NULL;
   s = ldap_str2syntax(syn_string, &ret, &errp, flag);
   if (ret) {
-    printf("Error: %d: %s", ret, errp);
-    /* XXX Do error handling... */
+    PyErr_SetString(SchemaError, errp);
     return NULL;
   }
   py_ret = PyList_New(4);
@@ -243,8 +242,7 @@
     return NULL;
   m = ldap_str2matchingrule(mr_string, &ret, &errp, flag);
   if (ret) {
-    printf("Error: %d: %s", ret, errp);
-    /* XXX Do error handling... */
+    PyErr_SetString(SchemaError, errp);
     return NULL;
   }
   py_ret = PyList_New(6);
@@ -285,5 +283,8 @@

 void
 LDAPinit_schema( PyObject* d ) {
+    SchemaError = PyErr_NewException("ldap.SchemaError",
+	LDAPexception_class, NULL);
+    PyDict_SetItemString(d, "SchemaError", SchemaError);
     LDAPadd_methods( d, methods );
 }
-- 
David Leonard                           David.Leonard at itee.uq.edu.au
Dept of Inf. Tech. and Elec. Engg   _   Ph:+61 404 844 850
The University of Queensland       |+|  http://www.itee.uq.edu.au/~leonard/
QLD 4072  AUSTRALIA               ~` '~ B73CD65FBEF4C089B79A8EBADF1A932F13EA0FC8






More information about the python-ldap mailing list