Strange behavior in Python-LDAP 2.0.0pre04

Mauro Cicognini mcicogni at siosistemi.it
Wed Jun 5 14:59:19 CEST 2002


Hi all,
I'd wish to bring to your attention a bizarre thing that I noticed 
yesterday.

The documentation, at chapter 1.1.5.1 "LDAP operations", in the 
description of the result() method, states that

[...]
The result() method returns a tuple of the form |(/result-type/, 
/result-data/)|.
[...]

Now, I found that this isn't always true in the current (2.0.0pre04) 
implementation: in fact, when result() is called with the 'all' 
parameter set to non-zero (which BTW is the default), it returns just 
the /result-data/ part.

In other words, in this case the method returns just a list instead of a 
(string, list) tuple. This breaks all of my code that uses asynchronous 
methods, like for instance this snippet:

    l = ldap.open(LDAPServer)
    msgid = l.simple_bind(username, password)
    status,res = l.result(msgid, all=1, timeout=60)
    if status != 'RES_BIND':
        return -1

will always raise a UnpackTuple exception, since the return value of 
result() will be [] instead of ('RES_BIND', None) as I expected.

Someone may argue that the 'all' parameter is only significant in 
search() responses; this is true, but it still shouldn't cause 
undocumented behavior in the called function, IMHO.
Anyway, this snippet breaks too:

    msgid =
    l.search("o=myCompany.com",ldap.SCOPE_SUBTREE,'uid=a*',['cn','mail'])
    status,res = l.result(msgid, all=1, timeout=60)
    if status != 'RES_SEARCH_RESULT':
        return -1


I tried to figure out if something was wrong on my part, or if I was 
calling some other method in the wrong way, but it appears everything is 
correct and that in fact it's the result() implementation within 
ldapobject.py that does this: the underlying C calls are correct, and 
they return the right data structure.
The code in the result() implementation, if returning all data, simply 
appears to throw away the result type; it builds a list containing all 
results, and returns just that.

I'd like to point out again that calling result() with all=0 would 
return a tuple as documented, instead.
Moreover, the 1.x version of PythonLDAP result() worked 'correctly', 
i.e. exactly as documented in all cases.

I think it's strange that nobody noticed this so far, so I do think I'm 
doing something wrong, or that I missed the discussion on this list 
about changing the result() behavior.

May anyone shed light on this subject?

Thank you in advance

Mauro Cicognini

P.S. This happens because I've finally managed to compile python-ldap 
under native Windows 32 (no Cygwin) and I was doing a bit of testing. 
This was the only problem I noticed so far, but it doesn't look to be 
related to the C part at all...

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ldap/attachments/20020605/ef8fb66d/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 2926 bytes
Desc: S/MIME Cryptographic Signature
URL: <http://mail.python.org/pipermail/python-ldap/attachments/20020605/ef8fb66d/attachment.bin>


More information about the python-ldap mailing list