Skip to content

Commit c2e045d

Browse files
tiranencukou
authored andcommitted
Add missing cidict.copy() method
The copy() method vanished when cidict was re-implemented on top of MutableMapping abstract base class. See: commit 2a2cef3 Fixes: python-ldap#387 Signed-off-by: Christian Heimes <cheimes@redhat.com>
1 parent 2647f59 commit c2e045d

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

Lib/ldap/cidict.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,14 @@ def clear(self):
5353
self._keys.clear()
5454
self._data.clear()
5555

56+
def copy(self):
57+
inst = self.__class__.__new__(self.__class__)
58+
inst._data = self._data.copy()
59+
inst._keys = self._keys.copy()
60+
return inst
61+
62+
__copy__ = copy
63+
5664
# Backwards compatibility
5765

5866
def has_key(self, key):

Tests/t_cidict.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,19 @@ def test_cidict_data(self):
7171
assert data == {'a': 1, 'b': 2}
7272
self.assertEqual(len(w), 1)
7373

74+
def test_copy(self):
75+
cix1 = ldap.cidict.cidict(
76+
{"a": 1, "B": 2}
77+
)
78+
cix2 = cix1.copy()
79+
self.assertEqual(cix1, cix2)
80+
cix1["c"] = 3
81+
self.assertNotIn("c", cix2)
82+
cix2["C"] = 4
83+
self.assertNotEqual(cix1, cix2)
84+
self.assertEqual(list(cix1.keys()), ["a", "B", "c"])
85+
self.assertEqual(list(cix2.keys()), ["a", "B", "C"])
86+
7487

7588
if __name__ == '__main__':
7689
unittest.main()

0 commit comments

Comments
 (0)
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