ldap.schema: str2objectclass() fails

Michael Ströder michael at stroeder.com
Tue Jul 30 22:20:44 CEST 2002


Michael Ströder wrote:
> Frankly I'd prefer to check the numerical error code in 
> ldap.schema.str2objectclass() and the other wrapper functions and raise 
> Python-declared exceptions instead of create the exception instances in 
> Modules/schema.c.

How about this approach assuming _ldap.str2objectclass() only 
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 = {
    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=0):
     r = ldap.functions._ldap_function_call(
       _ldap.str2objectclass,schema_element_str,schema_allow
     )
     if type(res)==type(0):
       raise ERRCODE2SCHERR.get(r,SchemaError)(
         r,schema_element_str
       )
     else:
       assert type(res)==type(())
       return r
------------------------- snip -------------------------

Ciao, Michael.







More information about the python-ldap mailing list