[python-ldap] Yet another Python3 port
Michael Ströder
michael at stroeder.com
Sat Nov 23 16:16:30 CET 2013
Raphaël Barrois wrote:
> The current python-ldap lib (without my fixes) uses only "str" (or "bytes")
> internally — the calling code should perform the "unicode to utf-8" conversion
> before sending anything, and the reverse when reading.
>
> This is quite cumbersome for non-pure-ascii systems (e.g, outside the US), but
> works not too bad for most commands where lookups, filters, etc. are pure ascii
> and thus silently converted into utf-8 bytes (as requested per the LDAP RFCs).
No application should ever rely on automatic string coercion when using
python-ldap! I even considered adding assertions making clear that Unicode
strings are not allowed. For Python 2 I'd just like to keep things as they are.
> With Python3, there is no auto-magic str/bytes conversion; we'll have to choose the behaviour regarding input *and* output:
> 1. Accept only Bytes, return only Bytes
> 2. Accept both Bytes and Text (with auto-magic cast, as in Py2), return Bytes (as in Py2)
> 2. Accept both Bytes and Text (with auto-magic cast, as in Py2), return Text
> 3. Accept only Text, return Text
Auto-magic casting costs performance.
Hint: Personally I'm sometimes using python-ldap for load-testing.
And as said numerous times: The goal for a Python3 module is not strict
backwards compability because the calling applications have to be
changed/re-written anyway.
The underlying C code is really cumbersome. So it would be my preference to
maintain that for Python 2 *and* 3 in a single code base. Then implement
different APIs by stacking wrapper classes on top of byte-oriented _ldap doing
the Py2 or Py3 specific stuff.
I'd accept an LDAP API for Python 3 which accepts and returns Unicode strings
for data for which *always* an (UTF-8) LDAP string representation is used:
Distinguished Names
LDAP filters
SASL strings
Attribute type names
LDAP URLs
compliant LDIF strings
Note that some old legacy LDAPv2 servers does not use UTF-8!
Some counter examples likely not obvious for most readers here:
Attribute values
`cred' for simple bind
For LDAPv3 extended controls and operations one would have to decide for each
special case.
Ciao, Michael.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 2398 bytes
Desc: S/MIME Cryptographic Signature
URL: <http://mail.python.org/pipermail/python-ldap/attachments/20131123/ab5c645a/attachment.bin>
More information about the python-ldap
mailing list