From 5960b9b68b5ddacd6f55a8d0c4abee4555e5ea39 Mon Sep 17 00:00:00 2001 From: Christian Heimes Date: Fri, 6 Nov 2020 17:14:37 +0100 Subject: [PATCH] Add missing cidict.copy() method The copy() method vanished when cidict was re-implemented on top of MutableMapping abstract base class. See: commit 2a2cef38feb7f259ea6b5735a6ce3e46812e217d Fixes: https://github.com/python-ldap/python-ldap/issues/387 Signed-off-by: Christian Heimes --- Lib/ldap/cidict.py | 8 ++++++++ Tests/t_cidict.py | 13 +++++++++++++ 2 files changed, 21 insertions(+) diff --git a/Lib/ldap/cidict.py b/Lib/ldap/cidict.py index a5ac29e0..ac19bd7d 100644 --- a/Lib/ldap/cidict.py +++ b/Lib/ldap/cidict.py @@ -53,6 +53,14 @@ def clear(self): self._keys.clear() self._data.clear() + def copy(self): + inst = self.__class__.__new__(self.__class__) + inst._data = self._data.copy() + inst._keys = self._keys.copy() + return inst + + __copy__ = copy + # Backwards compatibility def has_key(self, key): diff --git a/Tests/t_cidict.py b/Tests/t_cidict.py index 6878617e..7270bb03 100644 --- a/Tests/t_cidict.py +++ b/Tests/t_cidict.py @@ -72,6 +72,19 @@ def test_cidict_data(self): assert data == {'a': 1, 'b': 2} self.assertEqual(len(w), 1) + def test_copy(self): + cix1 = ldap.cidict.cidict( + {"a": 1, "B": 2} + ) + cix2 = cix1.copy() + self.assertEqual(cix1, cix2) + cix1["c"] = 3 + self.assertNotIn("c", cix2) + cix2["C"] = 4 + self.assertNotEqual(cix1, cix2) + self.assertEqual(list(cix1.keys()), ["a", "B", "c"]) + self.assertEqual(list(cix2.keys()), ["a", "B", "C"]) + if __name__ == '__main__': unittest.main() pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy