Browse Source

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
Corey Bryant 6 months ago
parent
commit
7734b7f45d
1 changed files with 5 additions and 2 deletions
  1. 5
    2
      ldappool/__init__.py

+ 5
- 2
ldappool/__init__.py View File

@@ -44,6 +44,7 @@ import time
44 44
 import ldap
45 45
 from ldap.ldapobject import ReconnectLDAPObject
46 46
 import six
47
+from six import PY2
47 48
 
48 49
 log = logging.getLogger(__name__)
49 50
 _utf8_encoder = codecs.getencoder('utf-8')
@@ -167,7 +168,8 @@ class ConnectionManager(object):
167 168
 
168 169
     def _match(self, bind, passwd):
169 170
         if passwd is not None:
170
-            passwd = utf8_encode(passwd)
171
+            if PY2:
172
+                passwd = utf8_encode(passwd)
171 173
         with self._pool_lock:
172 174
             inactives = []
173 175
 
@@ -240,7 +242,8 @@ class ConnectionManager(object):
240 242
         tries = 0
241 243
         connected = False
242 244
         if passwd is not None:
243
-            passwd = utf8_encode(passwd)
245
+            if PY2:
246
+                passwd = utf8_encode(passwd)
244 247
         exc = None
245 248
         conn = None
246 249
 

Loading…
Cancel
Save