diff options
author | Jon Wayne Parrott <jonwayne@google.com> | 2018-01-05 12:59:07 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-01-05 12:59:07 -0800 |
commit | 64d63ca71f28171dbd9e06b369ca2022383b9c50 (patch) | |
tree | abc38d850518e8724f6402301268aabae0bd965c /google | |
parent | 95fb93ef987cd824dba91a2f58eabe7eeee11f57 (diff) | |
download | python-api-core-64d63ca71f28171dbd9e06b369ca2022383b9c50.tar.gz |
api_core: Make PageIterator.item_to_value public. (#4702)
Diffstat (limited to 'google')
-rw-r--r-- | google/api_core/page_iterator.py | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/google/api_core/page_iterator.py b/google/api_core/page_iterator.py index 3d2a55b..0cf03a6 100644 --- a/google/api_core/page_iterator.py +++ b/google/api_core/page_iterator.py @@ -158,12 +158,25 @@ class Iterator(object): page_token=None, max_results=None): self._started = False self.client = client - self._item_to_value = item_to_value + """Optional[Any]: The client that created this iterator.""" + self.item_to_value = item_to_value + """Callable[Iterator, Any]: Callable to convert an item from the type + in the raw API response into the native object. Will be called with + the iterator and a + single item. + """ self.max_results = max_results + """int: The maximum number of results to fetch.""" + # The attributes below will change over the life of the iterator. self.page_number = 0 + """int: The current page of results.""" self.next_page_token = page_token + """str: The token for the next page of results. If this is set before + the iterator starts, it effectively offsets the iterator to a + specific starting point.""" self.num_results = 0 + """int: The total number of results fetched so far.""" @property def pages(self): @@ -335,7 +348,7 @@ class HTTPIterator(Iterator): if self._has_next_page(): response = self._get_next_page_response() items = response.get(self._items_key, ()) - page = Page(self, items, self._item_to_value) + page = Page(self, items, self.item_to_value) self._page_start(self, page, response) self.next_page_token = response.get(self._next_token) return page @@ -428,7 +441,7 @@ class _GAXIterator(Iterator): """ try: items = six.next(self._gax_page_iter) - page = Page(self, items, self._item_to_value) + page = Page(self, items, self.item_to_value) self.next_page_token = self._gax_page_iter.page_token or None return page except StopIteration: @@ -500,7 +513,7 @@ class GRPCIterator(Iterator): self.next_page_token = getattr(response, self._response_token_field) items = getattr(response, self._items_field) - page = Page(self, items, self._item_to_value) + page = Page(self, items, self.item_to_value) return page |