1
0
mirror of https://github.com/django/django.git synced 2024-12-26 02:56:25 +00:00
django/django/utils/itercompat.py
Aymeric Augustin ca07fda2ef [py3] Switched to Python 3-compatible imports.
xrange/range will be dealt with in a separate commit due to the huge
number of changes.
2012-07-22 09:29:56 +02:00

34 lines
1.0 KiB
Python

"""
Providing iterator functions that are not in all version of Python we support.
Where possible, we try to use the system-native version and only fall back to
these implementations if necessary.
"""
from django.utils.six.moves import builtins
import itertools
import warnings
def is_iterable(x):
"A implementation independent way of checking for iterables"
try:
iter(x)
except TypeError:
return False
else:
return True
def product(*args, **kwds):
warnings.warn("django.utils.itercompat.product is deprecated; use the native version instead",
PendingDeprecationWarning)
return itertools.product(*args, **kwds)
def all(iterable):
warnings.warn("django.utils.itercompat.all is deprecated; use the native version instead",
DeprecationWarning)
return builtins.all(iterable)
def any(iterable):
warnings.warn("django.utils.itercompat.any is deprecated; use the native version instead",
DeprecationWarning)
return builtins.any(iterable)