Commits

Sebastian Rahlf committed 642a459

In some cases it makes sense to still iterate over paginator pages rather than items. I therefore added a iterpages() method to BaseResultPaginator.

  • Participants
  • Parent commits f1e320c

Comments (0)

Files changed (2)

File amazonproduct/processors/__init__.py

 
     def __iter__(self):
         """
-        Iterate over all paginated results of ``fun``.
+        .. versionchanged:: 0.2.6
+           Iterates over items rather than pages. Use :meth:`iterpages` to do
+           the former.
+
+        Iterate over all paginated results of ``fun`` returning the items.
         """
-        # return cached first page
-        for item in self.iterate(self._first_page):
-            yield item
-        while self.current < self.pages and self.current < self.limit:
-            for item in self.iterate(self.page(self.current + 1)):
+        for page in self.iterpages():
+            for item in self.iterate(page):
                 yield item
 
     def __len__(self):
         self.current, self.pages, self.results = self.paginator_data(root)
         return root
 
+    def iterpages(self):
+        """
+        Iterates over all pages. Keep in mind that Amazon limits the number of
+        pages it makes available, although attribute ``pages`` may say
+        otherwise!
+        """
+        # return cached first page
+        yield self._first_page
+        while self.current < self.pages and self.current < self.limit:
+            yield self.page(self.current + 1)
+
     def paginator_data(self, node):
         """
         Extracts pagination data from XML node.

File tests/test_xml_responses.py

 
     @runfor(processors=['objectify'])
     def test_lookup_by_title(self, api):
-        for result in api.item_search('Books', Title='Harry Potter', limit=1):
-            for item in result.Items.Item:
-                assert item.ASIN == item.ASIN.pyval == item.ASIN.text
+        # TODO Does this test really make sense?
+        for item in api.item_search('Books', Title='Harry Potter', limit=1):
+            assert item.ASIN == item.ASIN.pyval == item.ASIN.text
         
 
 class TestSimilarityLookup (object):
         # default paginator type
         assert paginator.counter == ITEMS_PAGINATOR
 
-        for page, root in enumerate(paginator):
+        for page, root in enumerate(paginator.iterpages()):
             assert paginator.results == 281
             assert paginator.pages == 29
             assert paginator.current == page+1
     def test_itemsearch_related_items_pagination(self, api):
         paginator = api.item_search('All', Keywords='Michael',
             paginate=RELATEDITEMS_PAGINATOR)
-        pages = list(paginator)
+        pages = list(paginator.iterpages())
         assert len(pages) == len(paginator) == 5
         assert paginator.results == 556394
         assert paginator.current == 5