|
From: <mi...@st...> - 2002-07-30 20:23:09
|
Michael Str=F6der wrote:
> Frankly I'd prefer to check the numerical error code in=20
> ldap.schema.str2objectclass() and the other wrapper functions and raise=
=20
> Python-declared exceptions instead of create the exception instances in=
=20
> Modules/schema.c.
How about this approach assuming _ldap.str2objectclass() only=20
returns a error code as integer in case of an error?
------------------------- snip -------------------------
class SchemaError(Exception): pass
class SCHERR_OUTOFMEM(SchemaError): pass
class SCHERR_UNEXPTOKEN(SchemaError): pass
class SCHERR_NOLEFTPAREN(SchemaError): pass
class SCHERR_NORIGHTPAREN(SchemaError): pass
class SCHERR_NODIGIT(SchemaError): pass
class SCHERR_BADNAME(SchemaError): pass
class SCHERR_BADDESC(SchemaError): pass
class SCHERR_BADSUP(SchemaError): pass
class SCHERR_DUPOPT(SchemaError): pass
class SCHERR_EMPTY(SchemaError): pass
ERRCODE2SCHERR =3D {
1:SCHERR_OUTOFMEM
2:SCHERR_UNEXPTOKEN
3:SCHERR_NOLEFTPAREN
4:SCHERR_NORIGHTPAREN
5:SCHERR_NODIGIT
6:SCHERR_BADNAME
7:SCHERR_BADDESC
8:SCHERR_BADSUP
9:SCHERR_DUPOPT
10:SCHERR_EMPTY
}
# Wrapper functions to serialize calls into OpenLDAP libs with
# a module-wide thread lock
def str2objectclass(schema_element_str,schema_allow=3D0):
r =3D ldap.functions._ldap_function_call(
_ldap.str2objectclass,schema_element_str,schema_allow
)
if type(res)=3D=3Dtype(0):
raise ERRCODE2SCHERR.get(r,SchemaError)(
r,schema_element_str
)
else:
assert type(res)=3D=3Dtype(())
return r
------------------------- snip -------------------------
Ciao, Michael.
|