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

View File

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

View File

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