[openstack-dev] Sprint at Pycon: Port OpenStack to Python 3

Victor Stinner victor.stinner at enovance.com
Tue Apr 1 16:15:44 UTC 2014


Hi,

Le mardi 1 avril 2014, 09:11:52 John Dennis a écrit :
> What are the plans for python-ldap? Only a small part of python-ldap is
> pure python, are you also planning on tackling the CPython code?

Oh, python-ldap was just an example, I don't have concrete plan for each 
dependency. We are porting dependencies since some weeks, and many have 
already a pending patch or pull request:
https://wiki.openstack.org/wiki/Python3#Dependencies

I know the Python C API and I know well all the Unicode issues, so I'm not 
afraid of having to hack python-ldap if it's written in C ;-)

For your information, I am a Python core developer and I'm fixing Unicode 
issues in Python since 4 years or more :-) I also wrote a free ebook 
"Programming with Unicode":

   http://unicodebook.readthedocs.org/

> The biggest change in Py3 is unicode/str. The biggest pain point in the 2.x
> version of python-ldap is unicode <--> utf-8 at the API. Currently with
> python-ldap we have to encode most every parameter to utf-8 before
> calling python-ldap and then decode the result back from utf-8 to
> unicode.

According to the RFC 4511, LDAP speaks UTF-8 since the version 3. If the 
encoding is always UTF-8, it's much easier :-)

> I always thought this should have been done inside the
> python-ldap binding and it was a design failure it didn't correctly
> handle Python's unicode objects. FWIW the binding relied in CPython's
> automatic encoding conversion which applied the default encoding of
> ASCII which causes encoding encoding exceptions, the CPython binding
> just never used the correct argument processing in Py_ParseTuple() and
> PyParseTupleWithKeywords() which allows you to specify the desired
> encoding (the C API for LDAP specifies UTF-8 as does the RFC's).

python-ldap can be modified to handle the unicode type in Python 2 and use 
UTF-8.

> The Py3 porting work for python-ldap is probably going to have to
> address the unicode changes in Py3. If the Py3 port of python-ldap
> brings sanity to the unicode <--> utf-8 conversion then that makes a
> significant API change between the Py2 and Py3 versions of python-ldap
> making calling the python-ldap API significantly different between Py2
> and Py3. Does that mean you're also planning on backporting the Py3
> changes in python-ldap to Py2 to keep the API more or less consistent?

When I port an application to Python 3, I'm now trying to keep the same code 
base for both Python versions and have the same API.

I don't know python-ldap, I will have to take a look at its source code to see 
its current status and what should be done.

Victor



More information about the OpenStack-dev mailing list