/django/utils/itercompat.py

https://github.com/ptone/django-oldmaster · Python · 35 lines · 23 code · 5 blank · 7 comment · 3 complexity · 0337aff49d92798a2467f7c2d2236201 MD5 · raw file

  1. """
  2. Providing iterator functions that are not in all version of Python we support.
  3. Where possible, we try to use the system-native version and only fall back to
  4. these implementations if necessary.
  5. """
  6. import __builtin__
  7. import itertools
  8. import warnings
  9. def is_iterable(x):
  10. "A implementation independent way of checking for iterables"
  11. try:
  12. iter(x)
  13. except TypeError:
  14. return False
  15. else:
  16. return True
  17. def product(*args, **kwds):
  18. # PendingDeprecationWarning in 1.5, remove this comment when the Deprecations
  19. # will have been advanced for 1.5
  20. warnings.warn("django.utils.itercompat.product is deprecated; use the native version instead",
  21. PendingDeprecationWarning)
  22. return itertools.product(*args, **kwds)
  23. def all(iterable):
  24. warnings.warn("django.utils.itercompat.all is deprecated; use the native version instead",
  25. PendingDeprecationWarning)
  26. return __builtin__.all(iterable)
  27. def any(iterable):
  28. warnings.warn("django.utils.itercompat.any is deprecated; use the native version instead",
  29. PendingDeprecationWarning)
  30. return __builtin__.any(iterable)