| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
For this commit, moving some features of HTTPIterator constructor onto base class.
This was HTTP/JSON specific and belongs in the HTTP subclass.
Also updating the _GAXPageIterator mock to allow multiple pages.
Instead, using the page token directly from the page iterator passed in (this may occasionally be strange to a user, e.g. if the token is INITIAL_PAGE).
This somewhat of a cart-before-the-horse change, but is done this way to make the commit easier to understand, before unifying the two approaches via _next_page().
Also moving the token setting behavior from HTTPIterator._get_next_page_response() into _next_page().
Also a lint fix for an unimorted member and a unit test fix adding a page token to allow more paging.
|
This conceptually LGTM, I'll defer @tseaver for implementation review. |
Sorry, something went wrong.
|
@tseaver Can I get an amen? |
Sorry, something went wrong.
There was a problem hiding this comment.
Ouch! Commit-by-comit was a hard row to hoe, especially on the last commit, which blew away so much of what had been done before
Sorry, something went wrong.
|
|
||
| class Iterator(object): | ||
| class HTTPIterator(object): | ||
| """A generic class for iterating through Cloud JSON APIs list responses. |
| self.assertIs(iterator.client, client) | ||
| self.assertEqual(iterator.max_results, max_results) | ||
| self.assertEqual(list(iterator._page_iter), []) | ||
| self.assertFalse(iterator._page_increment) |
| page = Page(iterator, items, _item_to_topic) | ||
| iterator.next_page_token = page_iter.page_token or None | ||
| iterator.num_results += page.num_items | ||
| yield page |
| except StopIteration: | ||
| return None | ||
|
|
||
| def _wrap_gax(self, page_iter): |
| response = iterator._get_next_page_response() | ||
| self.assertEqual(response['items'], [{'name': key1}, {'name': key2}]) | ||
| self.assertEqual(iterator.page_number, 1) | ||
| self.assertEqual(iterator.next_page_token, token) |
|
@tseaver Sorry for the bait and switch at the end. It didn't become clear that a _next_page could do all the work until all pieces were moved. I considered rewriting the history but hoped it'd be clear enough, my bad. |
Sorry, something went wrong.
…ctor Refactor iterator to separate into HTTP/GAX iterators
Refactor iterator to separate into HTTP/GAX iterators
Refactor iterator to separate into HTTP/GAX iterators
| Back | FazBrowse Home | New Git URL |
NOTE: I'm happy to split this PR into tiny PRs if it makes review easy, though the commits are all pretty compact, so it should be reviewable commit-by-commit.