[python-ldap] Ldap connectors pool

Russell Jackson raj at csub.edu
Thu Sep 22 04:00:22 CEST 2011


On 09/20/2011 01:38 AM, Michael Ströder wrote:
> Tarek Ziadé wrote:
>> 2011/9/14 Michael Ströder<michael at stroeder.com>:
>>> Tarek Ziadé wrote:
>>>> I've been working on a pool class for ldap connectors, we're using for
>>>> the Firefox Sync server.
>>>> [..]
>>>> Example of usage:
>>>>
>>>>    cm = ConnectionManager('ldap://localhost')
>>>>
>>>>    with cm.connection('bind', 'password') as conn:
>>>>        ... do something with conn...
>>>
>>> Hmm, so it provides a slighty different API?
>>
>> The connection manager returns ldap objects actually,
>>
>> The addition is that you get a context manager to get that ldap object
>> and it takes care of recycling it when you get out if the with block.
>
> Hmm, being rather old-fashioned I'm not familiar with the context manager
> paradigm which was introduced in Python 2.5. It seems to be elegant but I'm
> not sure how common this is for developers using python-ldap.
>
> So far my posting "Minimum Python version supported by python-ldap?" sent 2nd
> August 2011 did not receive any answers...but this is relevant for that.

I'd personally like to see that at least old-style classes went away. 
Trying to write mixin classes that chain __init__ require using a 
derived LDAPObject that also inherits object and then overriding MRO 
(move the old-style classes to the end) in a meta-class so that the 
old-style class doesn't short-circuit super(). So whatever version of 
Python introduced unified types should be the minimal version.

As to the connection manager... couldn't you hijack __new__ in 
LDAPObject to return existing instances so that you could just use it 
the normal way without having the factory class?


More information about the python-ldap mailing list