[python-ldap] python3

Dusan Stefanik stefanik at dscon.sk
Wed Jun 15 20:15:07 CEST 2011


On 15/06/11 at 05:35pm, Michael Ströder wrote:
> Dusan Stefanik wrote:
> > I'm working on python-ldap for python3, my work is on right way.
> 
> Do you think it will be feasible to have a common code base for Python 2.x and
> Python 3.x at least for the C wrapper part?
Hmm I don't know. Look at diff (only Module dir).
First set of changes is PyString_* to PyBytes_* (Maybe PyUnicode_*) functions.
Second is PyInt_* to PyLong_*.
Third is C module creation and initialization (I don't know if I made it right but it works).

> 
> > There is principial question but I don't know answer.
> > In my work I changed all strings to bytes - it works.
> 
> That's what I would do within the C code in Modules/.
> 
> > So may better way will be using Unicode string internally.
> > What do you thing about it?
> 
> Hmm...not sure...
> 
> > Python on Linux use UCS2 schema, on some platform can use UCS4 schema (documentation write).
> > What schema using LDAP servers and does it matter?
> > What will be an impact to functionality?
> 
> 1. Attribute values can contain BLOBs like JPEG images, X.509 certs etc.
> There's no way to automagically converting attribute values to Unicode strings
> without looking in the relevant subschema or applying a-priori knowledge about
> the attribute type syntax.
> 
> 2. For LDAPv3 DNs and attribute types or similar have to be UTF-8 encoded
> before transmitted on the wire. For LDAPv2 it's T.61 but this varys depending
> on the server implementation/configuration.
> 
> => even when thinking more about it the best decision seems to simply use
> bytes in C code in Modules/.

I think so, but it's a little discomfort for user.

> 
> For 2. I was already thinking about automatic Unicode to bytes conversion in
> Lib/ldap/ldapobject.py with a charset as class attribute. But I have some
> doubts it's worth the effort. Can somebody point me to a *efficient* recipe
> how to decide whether to encode a Unicode string or pass along raw string
> which also works with Python 2.3? Yes, I know type(u'') but I'd like to avoid
> clutter all the method with such if-statements.
> 
> Ciao, Michael.
> 

Dusan
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ldap-Module.diff
Type: text/x-diff
Size: 27623 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-ldap/attachments/20110615/01532983/attachment-0001.diff>


More information about the python-ldap mailing list