Skip to content

Conversation

@dhermes
Copy link
Contributor

@dhermes dhermes commented Oct 26, 2016

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.

@dhermes dhermes added api: pubsub Issues related to the Pub/Sub API. api: core labels Oct 26, 2016
@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label Oct 26, 2016
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.
@theacodes
Copy link
Contributor

This conceptually LGTM, I'll defer @tseaver for implementation review.

@dhermes
Copy link
Contributor Author

dhermes commented Oct 26, 2016

@tseaver Can I get an amen?

58274923

Copy link
Contributor

@tseaver tseaver left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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


class Iterator(object):
class HTTPIterator(object):
"""A generic class for iterating through Cloud JSON APIs list responses.

This comment was marked as spam.

self.assertIs(iterator.client, client)
self.assertEqual(iterator.max_results, max_results)
self.assertEqual(list(iterator._page_iter), [])
self.assertFalse(iterator._page_increment)

This comment was marked as spam.

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

This comment was marked as spam.

except StopIteration:
return None

def _wrap_gax(self, page_iter):

This comment was marked as spam.

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)

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

@dhermes
Copy link
Contributor Author

dhermes commented Oct 26, 2016

@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.

@dhermes dhermes merged commit 5f97bc7 into googleapis:master Oct 27, 2016
@dhermes dhermes deleted the pubsub-iterators-refactor branch October 27, 2016 16:44
richkadel pushed a commit to richkadel/google-cloud-python that referenced this pull request May 6, 2017
…ctor

Refactor iterator to separate into HTTP/GAX iterators
parthea pushed a commit that referenced this pull request Nov 24, 2025
Refactor iterator to separate into HTTP/GAX iterators
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api: core api: pubsub Issues related to the Pub/Sub API. cla: yes This human has signed the Contributor License Agreement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants