From 6a46ed5c1f6b76097b81a9cf1e8899f44c38af52 Mon Sep 17 00:00:00 2001 From: Benjamin Dauvergne Date: Thu, 10 Jan 2019 19:08:30 +0100 Subject: [PATCH] wip --- src/ldaptools/synchronize.py | 2 +- src/ldaptools/utils.py | 9 +++++---- tox.ini | 5 +++-- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/ldaptools/synchronize.py b/src/ldaptools/synchronize.py index ed9f601..70a802c 100644 --- a/src/ldaptools/synchronize.py +++ b/src/ldaptools/synchronize.py @@ -236,7 +236,7 @@ class Synchronize(object): entries.sort(key=lambda (dn, entry): len(str2dn(dn))) for dn, entry in entries: for key in entry.keys(): - if not key in self.attributes: + if not str(key.lower()) in self.attributes: del entry[key] # First create, rename and update for batch in batch_generator(entries, self.BATCH_SIZE): diff --git a/src/ldaptools/utils.py b/src/ldaptools/utils.py index cf4a2e1..f45b611 100644 --- a/src/ldaptools/utils.py +++ b/src/ldaptools/utils.py @@ -1,4 +1,5 @@ import ldap.dn +from six import string_types # Copied from http://code.activestate.com/recipes/194371-case-insensitive-strings/ @@ -7,7 +8,7 @@ class istr(str): Performs like str except comparisons are case insensitive.""" def __init__(self, strMe): - str.__init__(self, strMe) + str.__init__(self) self.__lowerCaseMe = strMe.lower() def __repr__(self): @@ -80,7 +81,7 @@ class idict(dict): def findkey(self, item): """A caseless way of checking if a key exists or not. It returns None or the correct key.""" - if not isinstance(item, str): + if not isinstance(item, string_types): raise TypeError('Keywords for this object must be strings. You supplied %s' % type(item)) key = item.lower() try: @@ -147,13 +148,13 @@ class idict(dict): def has_key(self, item): """A case insensitive test for keys.""" - if not isinstance(item, str): + if not isinstance(item, string_types): return False # should never have a non-string key return item.lower() in self._keydict # does the key exist def __contains__(self, item): """A case insensitive __contains__.""" - if not isinstance(item, str): + if not isinstance(item, string_types): return False # should never have a non-string key return item.lower() in self._keydict # does the key exist diff --git a/tox.ini b/tox.ini index 063b256..efb94de 100644 --- a/tox.ini +++ b/tox.ini @@ -5,7 +5,7 @@ [tox] toxworkdir = {env:TMPDIR:/tmp}/tox-{env:USER}/ldaptools/ -envlist = coverage,package +envlist = coverage-ldappre3,coverage,package [testenv] usedevelop = true @@ -16,7 +16,8 @@ deps = pytest pytest-cov pytest-random - python-ldap<3 + ldappre3: python-ldap<3 + !ldappre3: python-ldap>=3 commands = py.test {env:COVERAGE:} {posargs:--random tests} -- 2.20.1