Skip to content

Commit 496e39f

Browse files
committed
Remove "itertools.permutations" backport.
1 parent 13a3aa3 commit 496e39f

File tree

1 file changed

+2
-28
lines changed

1 file changed

+2
-28
lines changed

test/high_availability/test_ha.py

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
# a replica set. Thus each method asserts everything we want to assert for a
2020
# given replica-set configuration.
2121

22+
import itertools
2223
import time
2324

2425
import ha_tools
@@ -53,33 +54,6 @@ def partition_nodes(nodes):
5354
return [_partition_node(node) for node in nodes]
5455

5556

56-
# Backport permutations to Python 2.4.
57-
# http://docs.python.org/2.7/library/itertools.html#itertools.permutations
58-
def permutations(iterable, r=None):
59-
pool = tuple(iterable)
60-
n = len(pool)
61-
if r is None:
62-
r = n
63-
if r > n:
64-
return
65-
indices = range(n)
66-
cycles = range(n, n-r, -1)
67-
yield tuple(pool[i] for i in indices[:r])
68-
while n:
69-
for i in reversed(range(r)):
70-
cycles[i] -= 1
71-
if cycles[i] == 0:
72-
indices[i:] = indices[i+1:] + indices[i:i+1]
73-
cycles[i] = n - i
74-
else:
75-
j = cycles[i]
76-
indices[i], indices[-j] = indices[-j], indices[i]
77-
yield tuple(pool[i] for i in indices[:r])
78-
break
79-
else:
80-
return
81-
82-
8357
class HATestCase(unittest.TestCase):
8458
"""A test case for connections to replica sets or mongos."""
8559

@@ -783,7 +757,7 @@ def test_pinning(self):
783757

784758
# Verify that changing the mode unpins the member. We'll try it for
785759
# every relevant change of mode.
786-
for mode0, mode1 in permutations(
760+
for mode0, mode1 in itertools.permutations(
787761
(PRIMARY, SECONDARY, SECONDARY_PREFERRED, NEAREST), 2
788762
):
789763
# Try reading and then changing modes and reading again, see if we

0 commit comments

Comments
 (0)