ipaldap, ldapupdate: Encoding fixes for Python 3

https://fedorahosted.org/freeipa/ticket/5638

Reviewed-By: Jan Cholasta <jcholast@redhat.com>
This commit is contained in:
Petr Viktorin
2015-10-14 15:02:51 +02:00
committed by Jan Cholasta
parent 831856ea55
commit fe7bd36728
2 changed files with 18 additions and 4 deletions

View File

@@ -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:

View File

@@ -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]