Commits

Anonymous committed 86464a0

Add code to work with other iterable containers, by Martin Kuzminski.

  • Participants
  • Parent commits 880eb1d

Comments (0)

Files changed (2)

    nothing with them, so it shouldn't allow them.
  - Import ``sqlalchemy.orm`` as well as ``sqlalchemy``. User Sybiam reports an
    error otherwise.
+ - Add code to work with other iterable containers, contributed by Marcin
+   Kuzminski.
 
 * webhelpers.pylonslib.flash:
 

webhelpers/paginate.py

     Auto-detect the kind of object and return a list/tuple
     to access items from the collection.
     """
-    # See if the collection is a sequence
+    # If the collection is a sequence we can use it directly
     if isinstance(obj, (list, tuple)):
         return obj
+
+    # If object is iterable we can use it directly
+    if hasattr(obj, "__iter__") and hasattr(obj, "__len__"):
+        return obj
+
     # Is SQLAlchemy 0.4 or better available? (0.3 is not supported - sorry)
     if sqlalchemy_available[:3] != '0.3':
         # Is the collection a query?
             or isinstance(obj, sqlalchemy.sql.expression.Select):
                 return _SQLAlchemySelect(obj, sqlalchemy_session)
 
-    raise TypeError("Sorry, your collection type is not supported by the paginate module. "
-            "You can either provide a list, a tuple, an SQLAlchemy 0.4 select object or an "
-            "SQLAlchemy 0.4 ORM-query object.")
+    raise TypeError("Sorry, your collection type is not supported by the "
+        "paginate module. You can provide a list, a tuple, a SQLAlchemy "
+        "select object or a SQLAlchemy ORM-query object.")
 
 class _SQLAlchemySelect(object):
     """