فهرست منبع

Remove compatibility code for itertools.permutations, in preparation of
dropping Python2.4 and 2.5 support.

Jelmer Vernooij 11 سال پیش
والد
کامیت
7e181d49a9
4فایلهای تغییر یافته به همراه10 افزوده شده و 42 حذف شده
  1. 1 35
      dulwich/_compat.py
  2. 4 3
      dulwich/tests/test_diff_tree.py
  3. 3 3
      dulwich/tests/test_objects.py
  4. 2 1
      dulwich/tests/test_walk.py

+ 1 - 35
dulwich/_compat.py

@@ -58,44 +58,10 @@ def unpack_from(fmt, buf, offset=0):
         return struct.unpack(fmt, b)
 
 
-try:
-    from itertools import permutations
-except ImportError:
-    # Implementation of permutations from Python 2.6 documentation:
-    # http://docs.python.org/2.6/library/itertools.html#itertools.permutations
-    # Copyright (c) 2001-2010 Python Software Foundation; All Rights Reserved
-    # Modified syntax slightly to run under Python 2.4.
-    def permutations(iterable, r=None):
-        # permutations('ABCD', 2) --> AB AC AD BA BC BD CA CB CD DA DB DC
-        # permutations(range(3)) --> 012 021 102 120 201 210
-        pool = tuple(iterable)
-        n = len(pool)
-        if r is None:
-            r = n
-        if r > n:
-            return
-        indices = range(n)
-        cycles = range(n, n-r, -1)
-        yield tuple(pool[i] for i in indices[:r])
-        while n:
-            for i in reversed(range(r)):
-                cycles[i] -= 1
-                if cycles[i] == 0:
-                    indices[i:] = indices[i+1:] + indices[i:i+1]
-                    cycles[i] = n - i
-                else:
-                    j = cycles[i]
-                    indices[i], indices[-j] = indices[-j], indices[i]
-                    yield tuple(pool[i] for i in indices[:r])
-                    break
-            else:
-                return
-
-
 try:
     all = all
 except NameError:
-    # Implementation of permutations from Python 2.6 documentation:
+    # Implementation of all from Python 2.6 documentation:
     # http://docs.python.org/2.6/library/functions.html#all
     # Copyright (c) 2001-2010 Python Software Foundation; All Rights Reserved
     # Licensed under the Python Software Foundation License.

+ 4 - 3
dulwich/tests/test_diff_tree.py

@@ -18,6 +18,10 @@
 
 """Tests for file and tree diff utilities."""
 
+from itertools import (
+    permutations,
+    )
+
 from dulwich.diff_tree import (
     CHANGE_MODIFY,
     CHANGE_RENAME,
@@ -39,9 +43,6 @@ from dulwich.diff_tree import (
 from dulwich.index import (
     commit_tree,
     )
-from dulwich._compat import (
-    permutations,
-    )
 from dulwich.object_store import (
     MemoryObjectStore,
     )

+ 3 - 3
dulwich/tests/test_objects.py

@@ -24,6 +24,9 @@
 
 from cStringIO import StringIO
 import datetime
+from itertools import (
+    permutations,
+    )
 import os
 import stat
 import warnings
@@ -31,9 +34,6 @@ import warnings
 from dulwich.errors import (
     ObjectFormatException,
     )
-from dulwich._compat import (
-    permutations,
-    )
 from dulwich.objects import (
     Blob,
     Tree,

+ 2 - 1
dulwich/tests/test_walk.py

@@ -18,9 +18,10 @@
 
 """Tests for commit walking functionality."""
 
-from dulwich._compat import (
+from itertools import (
     permutations,
     )
+
 from dulwich.diff_tree import (
     CHANGE_ADD,
     CHANGE_MODIFY,