summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPetr Viktorin <pviktori@redhat.com>2015-10-14 15:02:51 +0200
committerJan Cholasta <jcholast@redhat.com>2016-02-17 10:41:29 +0100
commitfe7bd367285618245ce1e203b49418d2ab675dbb (patch)
treedf299da8f3d1e6445b8ae543559b2625a2e1f3a7
parent831856ea55abb11139114c4c74563a13b6a1b6cf (diff)
downloadfreeipa-fe7bd367285618245ce1e203b49418d2ab675dbb.tar.gz
freeipa-fe7bd367285618245ce1e203b49418d2ab675dbb.tar.xz
freeipa-fe7bd367285618245ce1e203b49418d2ab675dbb.zip
ipaldap, ldapupdate: Encoding fixes for Python 3
https://fedorahosted.org/freeipa/ticket/5638 Reviewed-By: Jan Cholasta <jcholast@redhat.com>
-rw-r--r--ipapython/ipaldap.py14
-rw-r--r--ipaserver/install/ldapupdate.py8
2 files changed, 18 insertions, 4 deletions
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:
diff --git a/ipaserver/install/ldapupdate.py b/ipaserver/install/ldapupdate.py
index 285251363..95e35f697 100644
--- a/ipaserver/install/ldapupdate.py
+++ b/ipaserver/install/ldapupdate.py
@@ -32,6 +32,7 @@ import pwd
import fnmatch
import ldap
+import six
from ipaserver.install import installutils
from ipapython import ipautil, ipaldap
@@ -44,6 +45,9 @@ from ipapython.dn import DN
from ipapython.ipa_log_manager import log_mgr
from ipapython.ipautil import wait_for_open_socket
+if six.PY3:
+ unicode = str
+
UPDATES_DIR=paths.UPDATES_DIR
UPDATE_SEARCH_TIME_LIMIT = 30 # seconds
@@ -429,6 +433,10 @@ class LDAPUpdate:
"incorrect (%s)" % (v, data_source_name,
lcount, logical_line, e)
)
+ else:
+ for i, v in enumerate(value):
+ if isinstance(v, unicode):
+ value[i] = v.encode('utf-8')
if action != 'replace':
value = value[0]