Commits

Evgeniy Tatarkin committed 34641eb

move iterator to utils

Comments (0)

Files changed (4)

pomp/core/base.py

 """
 Base classes
 """
-import types
-
-
-def iterator(var):
-    if isinstance(var, types.StringTypes):
-        return iter((var,))
-    return iter(var)
 
 
 class BaseCrawler(object):

pomp/core/engine.py

 """
 Engine
 """
-from pomp.core.base import iterator
+from pomp.core.utils import iterator
 
 
 class Pomp(object):

pomp/core/utils.py

+import types
+
+
+def iterator(var):
+
+    if isinstance(var, types.GeneratorType):
+        return var
+
+    if isinstance(var, types.ListType) or isinstance(var, types.TupleType):
+        return iter(var)
+
+    return iter((var,))

tests/test_utils.py

+from pomp.core.utils import iterator
+
+
+def test_iterator():
+
+    assert hasattr(iterator('a'), '__iter__')
+    assert list(iterator('a')) == ['a']
+
+    assert hasattr(iterator(1), '__iter__')
+
+    assert hasattr(iterator(iterator('b')), '__iter__')