URL: https://github.com/freeipa/freeipa/pull/438 Author: HonzaCholasta Title: #438: ipaldap: preserve order of values in LDAPEntry._sync() Action: opened
PR body: """ In Python 2, the order was preserved by accident. This change makes sure the order is preserved in both Python 2 and 3. https://fedorahosted.org/freeipa/ticket/4985 """ To pull the PR as Git branch: git remote add ghfreeipa https://github.com/freeipa/freeipa git fetch ghfreeipa pull/438/head:pr438 git checkout pr438
From 8eab66daa2ba503bc9ae3ce0b5f650e330b1a371 Mon Sep 17 00:00:00 2001 From: Jan Cholasta <jchol...@redhat.com> Date: Tue, 7 Feb 2017 14:11:24 +0100 Subject: [PATCH] ipaldap: preserve order of values in LDAPEntry._sync() In Python 2, the order was preserved by accident. This change makes sure the order is preserved in both Python 2 and 3. https://fedorahosted.org/freeipa/ticket/4985 --- ipapython/ipaldap.py | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/ipapython/ipaldap.py b/ipapython/ipaldap.py index 497b947..24dc896 100644 --- a/ipapython/ipaldap.py +++ b/ipapython/ipaldap.py @@ -271,40 +271,48 @@ def _sync_attr(self, name): if nice == nice_sync and raw == raw_sync: return - nice_adds = set(nice) - set(nice_sync) - nice_dels = set(nice_sync) - set(nice) - raw_adds = set(raw) - set(raw_sync) - raw_dels = set(raw_sync) - set(raw) + nice_set = set(nice) + raw_set = set(raw) + nice_sync_set = set(nice_sync) + raw_sync_set = set(raw_sync) - for value in nice_dels: + for value in nice_sync: + if value in nice_set: + continue value = self._conn.encode(value) - if value in raw_adds: + if value in raw_set and value not in raw_sync_set: continue raw.remove(value) - for value in raw_dels: + for value in raw_sync: + if value in raw_set: + continue try: value = self._conn.decode(value, name) except ValueError as e: raise ValueError("{error} in LDAP entry '{dn}'".format( error=e, dn=self._dn)) - if value in nice_adds: + if value in nice_set and value not in nice_sync_set: continue nice.remove(value) - for value in nice_adds: + for value in nice: + if value in nice_sync_set: + continue value = self._conn.encode(value) - if value in raw_dels: + if value in raw_sync_set and value not in raw_set: continue raw.append(value) - for value in raw_adds: + for value in raw: + if value in raw_sync_set: + continue try: value = self._conn.decode(value, name) except ValueError as e: raise ValueError("{error} in LDAP entry '{dn}'".format( error=e, dn=self._dn)) - if value in nice_dels: + if value in nice_sync_set and value not in nice_set: continue nice.append(value)
-- Manage your subscription for the Freeipa-devel mailing list: https://www.redhat.com/mailman/listinfo/freeipa-devel Contribute to FreeIPA: http://www.freeipa.org/page/Contribute/Code