[python-ldap] O/R mapper

Michael Ströder michael at stroeder.com
Wed Apr 27 20:18:25 CEST 2011


Florian Friesdorf wrote:
> On Fri, 22 Apr 2011 17:15:25 +0200, Michael Ströder <michael at stroeder.com> wrote:
>> 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.
> 
>>> Attribute conversion maps could be generated from automatically parsing
>>> an ldap's schemas (if supported) or be provided by the user.
> 
> For fields were automatic conversion does not work, a conversion needs
> to be specified by the user of the library. 

Yes. So converting attribute values in LDAPObject._ldap_call() is the wrong place.

>> 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.
> 
> Thank you for the pointer, will definitely have a look at it.
> 
> Why do you keep this functionality in web2ldap and not in python-ldap?

The schema-ware classes are tightly coupled to web2ldap's HTML generating
needs and e.g. depend on pyweblib. You can use them as inspiration but not more.

Ciao, Michael.


More information about the python-ldap mailing list