|
@@ -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.
|