From 90eac76434e76b9ec52afabd695b2c06987668d6 Mon Sep 17 00:00:00 2001 From: jlaine Date: Tue, 1 Sep 2009 15:18:38 +0000 Subject: [PATCH] fix some character encoding issues git-svn-id: https://svn.bolloretelecom.eu/opensource/django-ldapdb/trunk@538 e071eeec-0327-468d-9b6a-08194a12b294 --- ldapdb/__init__.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/ldapdb/__init__.py b/ldapdb/__init__.py index 4cde6c0..c8c56ed 100644 --- a/ldapdb/__init__.py +++ b/ldapdb/__init__.py @@ -36,16 +36,17 @@ class LdapConnection(object): def __init__(self, server, bind_dn, bind_password): self.connection = ldap.initialize(server) self.connection.simple_bind_s(bind_dn, bind_password) + self.charset = "utf-8" def add_s(self, dn, modlist): mods = [] for field, value in modlist: - converted = convert(field, value, lambda x: x.encode('utf-8')) + converted = convert(field, value, lambda x: x.encode(self.charset)) if isinstance(converted, list): mods.append((field, converted)) else: mods.append((field, [converted])) - return self.connection.add_s(dn, mods) + return self.connection.add_s(dn.encode(self.charset), mods) def delete_s(self, dn): return self.connection.delete_s(dn) @@ -53,20 +54,20 @@ class LdapConnection(object): def modify_s(self, dn, modlist): mods = [] for op, field, value in modlist: - mods.append((op, field, convert(field, value, lambda x: x.encode('utf-8')))) - return self.connection.modify_s(dn, mods) + mods.append((op, field, convert(field, value, lambda x: x.encode(self.charset)))) + return self.connection.modify_s(dn.encode(self.charset), mods) def rename_s(self, dn, newrdn): - return self.connection.rename_s(dn, newrdn) + return self.connection.rename_s(dn.encode(self.charset), newrdn.encode(self.charset)) def search_s(self, base, scope, filterstr, attrlist): - results = self.connection.search_s(base, scope, filterstr, attrlist) + results = self.connection.search_s(base, scope, filterstr.encode(self.charset), attrlist) for dn, attrs in results: for field in attrs: if field == "member" or field == "memberUid": - attrs[field] = convert(field, attrs[field], lambda x: x.decode('utf-8')) + attrs[field] = convert(field, attrs[field], lambda x: x.decode(self.charset)) else: - attrs[field] = convert(field, attrs[field][0], lambda x: x.decode('utf-8')) + attrs[field] = convert(field, attrs[field][0], lambda x: x.decode(self.charset)) return results # FIXME: is this the right place to initialize the LDAP connection? -- 2.30.2