responses
responses ¶
PagedResponse ¶
PagedResponse(
session, response, limit=-1, key="pageItemList"
)
A generator that handles paginated responses by requesting the next page as you need it.
Source code in itkdb/responses.py
def __init__(self, session, response, limit=-1, key="pageItemList"):
self._pages = []
self._session = session
self._load(response)
self.yielded = 0
self.limit = limit if limit and limit > 0 else self.total
self.key = key
page_index property
¶
page_index: int
The pageIndex for the current page.
If there is no pageIndex, returns -1.
page_size property
¶
page_size: int
The pageSize for the current page.
If there is no pageSize, returns -1.
total property
¶
total: int
The total number of items (reported from the current page).
If there is no total, returns -1.
__next__ ¶
__next__()
Source code in itkdb/responses.py
def __next__(self):
if self.limit is not None:
if self.yielded >= self.limit:
raise StopIteration()
if self._list_index >= len(self.data):
self._next_page()
self._list_index += 1
self.yielded += 1
return self.data[self._list_index - 1]
Last update: April 19, 2023