From 147cad3511424478cf5b5854a578e53a145c4bc6 Mon Sep 17 00:00:00 2001 From: kakwa Date: Sat, 27 Jun 2015 22:35:34 +0200 Subject: [PATCH] fix unicode --- ldapcherry/__init__.py | 5 +++++ ldapcherry/backend/backendLdap.py | 18 +++++++++--------- resources/templates/adduser.tmpl | 1 + resources/templates/base.tmpl | 1 + resources/templates/error.tmpl | 1 + resources/templates/form.tmpl | 1 + resources/templates/index.tmpl | 1 + resources/templates/login.tmpl | 1 + resources/templates/modify.tmpl | 1 + resources/templates/navbar.tmpl | 1 + resources/templates/roles.tmpl | 1 + resources/templates/searchadmin.tmpl | 1 + resources/templates/searchuser.tmpl | 1 + resources/templates/selfmodify.tmpl | 1 + 14 files changed, 26 insertions(+), 9 deletions(-) diff --git a/ldapcherry/__init__.py b/ldapcherry/__init__.py index c077b8c..0172025 100644 --- a/ldapcherry/__init__.py +++ b/ldapcherry/__init__.py @@ -372,6 +372,11 @@ class LdapCherry(object): attrid = self.attributes.backend_attributes[b][attr] if not attr in ret: ret[attrid] = tmp[attr] + + cherrypy.log.error( + msg = "user '" + username + "' attributes " + str(ret), + severity = logging.DEBUG + ) return ret def _parse_params(self, params): diff --git a/ldapcherry/backend/backendLdap.py b/ldapcherry/backend/backendLdap.py index 3585a3c..2a94d71 100644 --- a/ldapcherry/backend/backendLdap.py +++ b/ldapcherry/backend/backendLdap.py @@ -163,10 +163,10 @@ class Backend(ldapcherry.backend.Backend): return dn_entry def _str(self, s): - try: - return str(s) - except UnicodeEncodeError: - return unicode(s).encode('unicode_escape') + return s.encode('utf-8') + + def _uni(self, s): + return s.decode('utf-8') def auth(self, username, password): @@ -303,9 +303,9 @@ class Backend(ldapcherry.backend.Backend): for attr in attrs_tmp: value_tmp = attrs_tmp[attr] if len(value_tmp) == 1: - attrs[attr] = value_tmp[0] + attrs[attr] = self._uni(value_tmp[0]) else: - attrs[attr] = value_tmp + attrs[attr] = map(self._uni, value_tmp) if self.key in attrs: ret[attrs[self.key]] = attrs @@ -317,9 +317,9 @@ class Backend(ldapcherry.backend.Backend): for attr in attrs_tmp: value_tmp = attrs_tmp[attr] if len(value_tmp) == 1: - ret[attr] = value_tmp[0] + ret[attr] = self._uni(value_tmp[0]) else: - ret[attr] = value_tmp + ret[attr] = map(self._uni, value_tmp) return ret def get_groups(self, username): @@ -333,5 +333,5 @@ class Backend(ldapcherry.backend.Backend): groups = self._search(searchfilter, NO_ATTR, self.groupdn) ret = [] for entry in groups: - ret.append(entry[0]) + ret.append(self._uni(entry[0])) return ret diff --git a/resources/templates/adduser.tmpl b/resources/templates/adduser.tmpl index 060cf4a..21af83f 100644 --- a/resources/templates/adduser.tmpl +++ b/resources/templates/adduser.tmpl @@ -1,3 +1,4 @@ +## -*- coding: utf-8 -*- <%inherit file="navbar.tmpl"/> <%block name="core">
diff --git a/resources/templates/base.tmpl b/resources/templates/base.tmpl index 84478e1..db95f3c 100644 --- a/resources/templates/base.tmpl +++ b/resources/templates/base.tmpl @@ -1,3 +1,4 @@ +## -*- coding: utf-8 -*- diff --git a/resources/templates/error.tmpl b/resources/templates/error.tmpl index a59a667..b8fe7ba 100644 --- a/resources/templates/error.tmpl +++ b/resources/templates/error.tmpl @@ -1,3 +1,4 @@ +## -*- coding: utf-8 -*- <%inherit file="navbar.tmpl"/> <%block name="core">
diff --git a/resources/templates/form.tmpl b/resources/templates/form.tmpl index bf03400..b947517 100644 --- a/resources/templates/form.tmpl +++ b/resources/templates/form.tmpl @@ -1,3 +1,4 @@ +## -*- coding: utf-8 -*- <% len_attr = len(attributes) switch = len_attr / 2 diff --git a/resources/templates/index.tmpl b/resources/templates/index.tmpl index de01293..e35ba1b 100644 --- a/resources/templates/index.tmpl +++ b/resources/templates/index.tmpl @@ -1,3 +1,4 @@ +## -*- coding: utf-8 -*- <%inherit file="navbar.tmpl"/> <%block name="core"> diff --git a/resources/templates/login.tmpl b/resources/templates/login.tmpl index 361ac04..282e7ec 100644 --- a/resources/templates/login.tmpl +++ b/resources/templates/login.tmpl @@ -1,3 +1,4 @@ +## -*- coding: utf-8 -*- <%inherit file="base.tmpl"/> <%block name="core">
diff --git a/resources/templates/modify.tmpl b/resources/templates/modify.tmpl index b87f209..e6868b9 100644 --- a/resources/templates/modify.tmpl +++ b/resources/templates/modify.tmpl @@ -1,3 +1,4 @@ +## -*- coding: utf-8 -*- <%inherit file="navbar.tmpl"/> <%block name="core">
diff --git a/resources/templates/navbar.tmpl b/resources/templates/navbar.tmpl index b98886b..806b48a 100644 --- a/resources/templates/navbar.tmpl +++ b/resources/templates/navbar.tmpl @@ -1,3 +1,4 @@ +## -*- coding: utf-8 -*- #<%inherit file="base.tmpl"/> <%block name="navbar">
diff --git a/resources/templates/roles.tmpl b/resources/templates/roles.tmpl index b65a06e..d97457d 100644 --- a/resources/templates/roles.tmpl +++ b/resources/templates/roles.tmpl @@ -1,3 +1,4 @@ +## -*- coding: utf-8 -*-