responses
responses ¶
PagedResponse ¶
PagedResponse(
session,
response,
history=False,
limit=-1,
key="pageItemList",
)
A generator that handles paginated responses by requesting the next page as you need it.
Changed in version 0.4.6
- added
history
argument
Source code in src/itkdb/responses.py
def __init__(self, session, response, history=False, limit=-1, key="pageItemList"):
# self._load() relies on self.history
self.history = history
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.
__bool__ ¶
__bool__()
Source code in src/itkdb/responses.py
def __bool__(self):
return bool(self.total)
__next__ ¶
__next__()
Source code in src/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]