From 7734b7f45d61a22ebc0ce204304486b7484d697a Mon Sep 17 00:00:00 2001 From: Corey Bryant Date: Wed, 17 Oct 2018 13:18:35 -0400 Subject: [PATCH] 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 --- ldappool/__init__.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/ldappool/__init__.py b/ldappool/__init__.py index 6bc52f0..bf7c1be 100644 --- a/ldappool/__init__.py +++ b/ldappool/__init__.py @@ -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