Remove usage of six library

... because now ldappool supports Python 3 only.

Change-Id: Ibeb60dbc81ef5b03f0732439ed07c2b672e78df5
This commit is contained in:
Takashi Kajinami 2021-08-22 13:45:22 +09:00 committed by Joel Capitao
parent 73b1b09b25
commit 0a56650693
2 changed files with 6 additions and 17 deletions

@ -35,7 +35,6 @@
# ***** END LICENSE BLOCK ***** # ***** END LICENSE BLOCK *****
""" LDAP Connection Pool. """ LDAP Connection Pool.
""" """
import codecs
from contextlib import contextmanager from contextlib import contextmanager
import logging import logging
from threading import RLock from threading import RLock
@ -45,29 +44,26 @@ import ldap
from ldap.ldapobject import ReconnectLDAPObject from ldap.ldapobject import ReconnectLDAPObject
from prettytable import PrettyTable from prettytable import PrettyTable
import re import re
import six
from six import PY2
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
_utf8_encoder = codecs.getencoder('utf-8')
def utf8_encode(value): def utf8_encode(value):
"""Encode a basestring to UTF-8. """Encode a basestring to UTF-8.
If the string is unicode encode it to UTF-8, if the string is If the value is string, encode it to UTF-8, if the value is
str then assume it's already encoded. Otherwise raise a TypeError. bytes then assume it's already encoded. Otherwise raise a TypeError.
:param value: A basestring :param value: A basestring
:returns: UTF-8 encoded version of value :returns: UTF-8 encoded version of value
:raises TypeError: If value is not basestring :raises TypeError: If value is not basestring
""" """
if isinstance(value, six.text_type): if isinstance(value, str):
return _utf8_encoder(value)[0] return value.encode('utf-8')
elif isinstance(value, six.binary_type): elif isinstance(value, bytes):
return value return value
else: else:
raise TypeError("bytes or Unicode expected, got %s" raise TypeError("bytes or str expected, got %s"
% type(value).__name__) % type(value).__name__)
@ -169,9 +165,6 @@ class ConnectionManager(object):
return len(self._pool) return len(self._pool)
def _match(self, bind, passwd): def _match(self, bind, passwd):
if passwd is not None:
if PY2:
passwd = utf8_encode(passwd)
with self._pool_lock: with self._pool_lock:
inactives = [] inactives = []
@ -242,9 +235,6 @@ class ConnectionManager(object):
:raises BackendError: If unable to connect to LDAP :raises BackendError: If unable to connect to LDAP
""" """
connected = False connected = False
if passwd is not None:
if PY2:
passwd = utf8_encode(passwd)
# If multiple server URIs have been provided, loop through # If multiple server URIs have been provided, loop through
# each one in turn in case of connection failures (server down, # each one in turn in case of connection failures (server down,

@ -1,3 +1,2 @@
python-ldap>=3.0.0 # PSF python-ldap>=3.0.0 # PSF
PrettyTable>=0.7.2 PrettyTable>=0.7.2
six>=1.10.0 # MIT