[python-ldap] O/R mapper

Michael Ströder michael at stroeder.com
Fri Apr 22 17:15:25 CEST 2011

Florian Friesdorf wrote:
> For me it looks like the attribute conversions could be handled by
> subclassing and overwriting _ldap_call [3], in pseudo-code:
> def _ldap_call(self, func, *args, **kwargs):
>     args = deep_utf8_copy(args)
>     kwargs = deep_utf8_copy(kwargs)
>     res = super(...)...
>     if not self.convmap:
>        return res
>     return check_for_things_to_convert(res, self.convmap)

http://www.freeipa.org is doing something like this AFAICT with decorators.
Check their code.

But as repeated on this mailing list several times: In general this won't work
without having knowledge of the subschema. E.g. your automatic conversion
won't work for attributes like jpegPhoto, userCertificate, userPKCS12 etc.

So you could have a look how web2ldap deals with all that based on
schema-aware classes. Basically there are classes for each LDAP syntax
registered by syntax OID with several possibilities to override that for
certain attribute types. web2ldap itself is only interested in (Unicode)
strings. One could extend the concept to convert to native Python data types.

Ciao, Michael.

More information about the python-ldap mailing list