LDAP/LDIF Parsing
Hallvard B Furuseth
h.b.furuseth at usit.uio.no
Fri Feb 2 07:48:47 EST 2007
Bruno Desthuilliers writes:
> class LdapObject(object):
> (...)
> def __getattr__(self, name):
> try:
> data = self._record[name]
> except KeyError:
> raise AttributeError(
> "object %s has no attribute %s" % (self, name)
> )
Note that LDAP attribute descriptions may be invalid Python
attribute names. E.g.
{...
'title;lang-en': ['The Boss']
'title;lang-no': ['Sjefen']}
So you'd have to call getattr() explicitly to get at all the attributes
this way.
> 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.
--
Regards,
Hallvard
More information about the Python-list
mailing list