浏览代码

Replace the check for an object being iterable by a Python 2.2 compatible way.

The current implemention required Python 2.6.
Vincent Driessen 15 年之前
父节点
当前提交
1b9ef5cb8f
共有 2 个文件被更改,包括 11 次插入3 次删除
  1. 3 3
      celery/task/schedules.py
  2. 8 0
      celery/utils/__init__.py

+ 3 - 3
celery/task/schedules.py

@@ -1,7 +1,7 @@
 from datetime import datetime
-from collections import Iterable
 from pyparsing import Word, Literal, ZeroOrMore, Optional, Group, StringEnd, alphas
 
+from celery.utils import is_iterable
 from celery.utils.timeutils import timedelta_seconds, weekday, remaining
 
 
@@ -185,11 +185,11 @@ class crontab(schedule):
             result = crontab_parser(max_).parse(cronspec)
         elif isinstance(cronspec, set):
             result = cronspec
-        elif isinstance(cronspec, Iterable):
+        elif is_iterable(cronspec):
             result = set(cronspec)
         else:
             raise TypeError("Argument cronspec needs to be of any of the " + \
-                    "following types: int, basestring, set, or Iterable. " + \
+                    "following types: int, basestring, or an iterable type. " + \
                     "'%s' was given." % type(cronspec))
 
         # assure the result does not exceed the max

+ 8 - 0
celery/utils/__init__.py

@@ -90,6 +90,14 @@ def padlist(container, size, default=None):
     return list(container)[:size] + [default] * (size - len(container))
 
 
+def is_iterable(obj):
+    try:
+        iter(obj)
+    except TypeError:
+        return False
+    return True
+
+
 def mitemgetter(*items):
     """Like :func:`operator.itemgetter` but returns ``None`` on missing items
     instead of raising :exc:`KeyError`."""