PY3: switch to using unicode text values

In Python 3, python-ldap no longer allows bytes for DN/RDN/field
names. Instead, text values are represented as str, the Unicode
text type.

This patch updates the code to adhere to this behavior.

More details about byte/str usage in python-ldap can be found at:
http://www.python-ldap.org/en/latest/bytes_mode.html#bytes-mode

Change-Id: I9ef10432229aaffe4ac9bd733d608098cdae3b9a
Partial-Bug: #1798184
This commit is contained in:
Corey Bryant 2018-10-17 13:18:35 -04:00
parent 3c1ce2d830
commit 7734b7f45d
1 changed files with 5 additions and 2 deletions

View File

@ -44,6 +44,7 @@ import time
import ldap
from ldap.ldapobject import ReconnectLDAPObject
import six
from six import PY2
log = logging.getLogger(__name__)
_utf8_encoder = codecs.getencoder('utf-8')
@ -167,7 +168,8 @@ class ConnectionManager(object):
def _match(self, bind, passwd):
if passwd is not None:
passwd = utf8_encode(passwd)
if PY2:
passwd = utf8_encode(passwd)
with self._pool_lock:
inactives = []
@ -240,7 +242,8 @@ class ConnectionManager(object):
tries = 0
connected = False
if passwd is not None:
passwd = utf8_encode(passwd)
if PY2:
passwd = utf8_encode(passwd)
exc = None
conn = None