From fe7bd367285618245ce1e203b49418d2ab675dbb Mon Sep 17 00:00:00 2001 From: Petr Viktorin Date: Wed, 14 Oct 2015 15:02:51 +0200 Subject: ipaldap, ldapupdate: Encoding fixes for Python 3 https://fedorahosted.org/freeipa/ticket/5638 Reviewed-By: Jan Cholasta --- ipapython/ipaldap.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'ipapython') diff --git a/ipapython/ipaldap.py b/ipapython/ipaldap.py index 28bfcb5c2..7522c504b 100644 --- a/ipapython/ipaldap.py +++ b/ipapython/ipaldap.py @@ -346,11 +346,16 @@ class LDAPEntry(collections.MutableMapping): return self._names[name] if self._conn.schema is not None: + if six.PY2: + encoded_name = name.encode('utf-8') + else: + encoded_name = name attrtype = self._conn.schema.get_obj( - ldap.schema.AttributeType, name.encode('utf-8')) + ldap.schema.AttributeType, encoded_name) if attrtype is not None: for altname in attrtype.names: - altname = altname.decode('utf-8') + if six.PY2: + altname = altname.decode('utf-8') self._names[altname] = name self._names[name] = name @@ -774,8 +779,9 @@ class LDAPClient(object): if not self._decode_attrs: return bytes - if isinstance(name_or_oid, unicode): - name_or_oid = name_or_oid.encode('utf-8') + if six.PY2: + if isinstance(name_or_oid, unicode): + name_or_oid = name_or_oid.encode('utf-8') # Is this a special case attribute? if name_or_oid in self._SYNTAX_OVERRIDE: -- cgit