[python-ldap] simple_bind_s, no exception on empty password

Michael Wood esiotrot at gmail.com
Mon Dec 10 14:39:58 CET 2012


On 8 December 2012 09:01, Chris Gray <fathed at gmail.com> wrote:
>
> Hmm, that's handy info. And that seems to work:
>
> if ldap_conn.whoami_s().lower() == "u:" + ldap_user.lower():
>
> This of course leads to new problems.
> First, .lower() says it is to be considered deprecated.
> http://docs.python.org/2/library/string.html
>
> After searching the webs, everything I see still uses .lower() or
> .upper(), even if it says it's written for Python3. So, not really sure if I
> should be concerned about that for now.

No.  The docs are perhaps not as clear as they could be, but what they
are trying to say is this.  The following is deprecated:

import string
string.lower("Something")

The following is the recommended way (i.e. exactly what you're doing):

"Something".lower()

> And the second issue,
[...]
> I guess I would need a python3 version of the python-ldap library to solve
> that, meaning I should wait for the unicode issue, or try something like
> this:
> ldap_conn.whoami_s().decode('unicode_escape').encode('iso8859-1').decode('utf8'),
> which does set the type to unicode. This does work, just seems messy.

That looks completely wrong to me.  You can't assume that something
that is valid ISO 8859-1 will also be valid UTF-8.

>>> x = "\\u00a0"
>>> x.decode("unicode_escape").encode("iso8859-1").decode("utf8")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.6/encodings/utf_8.py", line 16, in decode
    return codecs.utf_8_decode(input, errors, True)
UnicodeDecodeError: 'utf8' codec can't decode byte 0xa0 in position 0:
unexpected code byte

Anyway, the result of the .decode("unicode_escape") is already a
unicode string, so why encode and decode it again?

Does ldap_conn.whoami_s() return a string with \uNNNN escape sequences in it?

-- 
Michael Wood <esiotrot at gmail.com>


More information about the python-ldap mailing list