patch for Internationalization support (iconv)
michael at stroeder.com
Tue Oct 16 18:10:41 CEST 2001
Steffen Ries wrote:
> js9s at netscape.net writes:
> > I just worked out the python-ldap so that it will convert the local
> > characters to utf8 or vice versa according to the user locale setup.
> > This is done because OpenLdap currently only support utf8, one has
> > to make the translation mannually getting in or out of openldap.
> I would be careful with this patch.
> It looks to me that you are converting *every* ldap attribute from the
> current locale encoding to UTF-8 (and vice versa). This takes care of
> the most common attributes, but it affects binary attributes as well,
> which it shouldn't.
Exactly. Without knowing the schema (syntax of attribute here) used
on the server a LDAP application should not simply assume UTF-8.
Also a really compliant application should look at the LDAP version
in use. LDAPv2 assumes T.61.
> IMHO a better approach would be to allow Python Unicode strings as
> well as regular strings for writing attributes, then encode unicode
> strings to UTF-8.
The application has to know the schema and therefore the application
is responsible for encoding before passing strings to python-ldap.
python-ldap is too low-level for that. I would even disallow passing
Unicode strings to python-ldap.
> For reading from LDAP, I'm not sure what the best approach would
> be. E.g. if the attribute type syntax is "Directory String", create a
> unicode string, otherwise create a literal string. But how do you know
> the attribute syntax?
Again: python-ldap is too low-level for that. Don't mess with
different string types! And rethink why default encoding in Python's
Unicode support is ASCII.
> Maybe it is best to leave the attributes as they
> are and leave the encoding to the user...
More information about the python-ldap