[python3-ldap] Feedback on aspects of python3-ldap's API

python3ldap python3ldap at gmail.com
Wed Sep 24 09:40:02 CEST 2014


Hello Florian,
the connection context works as you state:

>>> with Connection('server', 'admin', 'password') as c:
...  c.search('o=test', '(cn=*)')
...  r = c.response

>>> str(c)
'ldap://server - cleartext - user: admin - unbound - closed - tls not
started - not listening - SyncWaitStrategy'

(so the connection is open, bound, operations are executed and then
the connection is unbounded)

 the only difference is that if the connection was already defined it
retains the same state it had before entering the context:

c = Connection('server', 'admin', 'password')
c.bind()

with c:
...  c.search('o=test', '(cn=*)')
...  r = c.response

>>> str(c)
'ldap://server - cleartext - user: admin - unbound - closed - tls not
started - not listening - SyncWaitStrategy'

I don't think that the syntax "with c.bind():" is more clear because
the Connection object does exist indipendently from the bind()
operation. (LDAP protocol states that you can even send operations
without binding).

Bye,
Giovanni


2014-09-23 12:31 GMT+02:00 Florian Friesdorf <flo at chaoflow.net>:
>
> Hi Giovanni,
>
> On Tue, Sep 23 2014, python3ldap wrote:
>> Regarding the connection context manager there is no magic at all in
>> it. As stated in the docs the connection retains the status it had
>> before entering the context. This has been done because it's quite
>> expensive to bind a connection each time you get in the context, so
>> the connection is not destroyed when exiting it. Furthermore if you
>> use "lazy" connections (that bind only if there is some real operation
>> to perform) you gain a speed boost in long standing routines (I work
>> mainly on identity management systems and this has proven useful).
>
>     with Connection(...) as c:
>         ...
>
> I would expect the connection to be closed when the context is left,
> compare to:
>
>     with open('file') as f:
>         ...
>
> To change the state of binding as part of a context manager I would
> expect something like:
>
>     c = Connection(...)   # unbound
>     with c.bind(...):
>         ...
>
> best regards
> florian
>
>> 2014-09-22 19:15 GMT+02:00 Florian Friesdorf <flo at chaoflow.net>:
>>>
>>> Hi Giovanni,
>>>
>>> On community.plone.org[1] you are asking what we consider confusing
>>> about python3-ldap's API. I hope it is in your interest that I post this
>>> feedback here to the python3-ldap list. To the other aspects of your
>>> posting I will reply on community.plone.org
>>>
>>> [1] https://community.plone.org/t/ldap-status-quo-and-where-to-go-from-here/285
>>>
>>> On Sun, Sep 21 2014, cannata_g wrote:
>>>> Hello everybody,
>>>> I'm the author of python3-ldap. I read in your message that you think
>>>> that the python3-ldap API is "confusing". I'd like to know what you
>>>> mean by that, are you referring to the documentation (still not
>>>> completed) or to the API itself?.
>>>
>>> The opinion that python3-ldap's API is confusing to us, was formed after
>>> a brief look at the quick tour[2]:
>>>
>>> [2] http://pythonhosted.org/python3-ldap/quicktour.html
>>>
>>> To perform a search, python3-ldap uses a connection object on which a
>>> search method is called with the search parameters. The result is not
>>> returned but instead there are .result and .response attributes on the
>>> connection.
>>>
>>> When using a connection as context-manager, the connection lives on
>>> after leaving the context. Within the context the binding to the ldap
>>> server is magically changed.
>>>
>>> Both these things we consider rather untypical for pythonic APIs.
>>>
>>> regards
>>> Marko and Florian
>>> --
>>> Florian Friesdorf <flo at chaoflow.net>
>>>   GPG FPR: 7A13 5EEE 1421 9FC2 108D  BAAF 38F8 99A3 0C45 F083
>>> Jabber/XMPP: flo at chaoflow.net
>>> IRC: chaoflow on freenode,ircnet,blafasel,OFTC
>>>
>>> _______________________________________________
>>> python3-ldap mailing list
>>> python3-ldap at python.org
>>> https://mail.python.org/mailman/listinfo/python3-ldap
>>>
>
> --
> Florian Friesdorf <flo at chaoflow.net>
>   GPG FPR: 7A13 5EEE 1421 9FC2 108D  BAAF 38F8 99A3 0C45 F083
> Jabber/XMPP: flo at chaoflow.net
> IRC: chaoflow on freenode,ircnet,blafasel,OFTC


More information about the python3-ldap mailing list