From de6fd15ef6b7d8fd445cf621de2cb085a28e1fc3 Mon Sep 17 00:00:00 2001 From: Takashi Kajinami Date: Sun, 22 Aug 2021 13:45:22 +0900 Subject: [PATCH] Remove usage of six library ... because now ldappool supports Python 3 only. Change-Id: Ibeb60dbc81ef5b03f0732439ed07c2b672e78df5 --- ldappool/__init__.py | 22 ++++++---------------- requirements.txt | 1 - 2 files changed, 6 insertions(+), 17 deletions(-) diff --git a/ldappool/__init__.py b/ldappool/__init__.py index 738cff8..e9c8971 100644 --- a/ldappool/__init__.py +++ b/ldappool/__init__.py @@ -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, diff --git a/requirements.txt b/requirements.txt index 259254f..9f5f7d3 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,2 @@ python-ldap>=3.0.0 # PSF PrettyTable>=0.7.2 -six>=1.10.0 # MIT