LDAP/LDIF Parsing

Hallvard B Furuseth h.b.furuseth at usit.uio.no
Fri Feb 2 09:27:59 EST 2007


Bruno Desthuilliers writes:
>Hallvard B Furuseth a écrit :
>>>      else:
>>>        # all LDAP attribs are multivalued by default,
>>>        # even when the schema says they are monovalued
>>>        if len(data) == 1:
>>>           return data[0]
>>>        else:
>>>           return data[:]
>> IMHO, this just complicates the client code since the client needs to
>> inserts checks of isinstance(return value, list) all over the place.
>> Better to have a separate method which extracts just the first value of
>> an attribute, if you want that.
>
> Most of the times, in a situation such as the one described by the OP,
> one knows by advance if a given LDAP attribute will be used as
> monovalued or multivalued. Well, this is at least my own experience...

But if the attribute is multivalued, you don't know if it will contain
just one value or not.  If you expect telephoneNumber to be multivalued,
but receive just one value '123',
      for value in foo.telephoneNumber: print value
will print
	1
	2
	3

BTW, Cruelemort, remember that attribute names are case-insensitive.  If
you ask the server to for attribute "cn", it might still return "CN".

-- 
Hallvard



More information about the Python-list mailing list