Skip to content

responses

responses

log module-attribute

log = logging.getLogger(__name__)

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

data property

data: dict | list[dict]

The data contained on the most recent page retrieved.

error property

error: dict

The uuAppErrorMap for the current page.

key instance-attribute

key = key

last_page property

last_page: dict

The most recent page retrieved.

limit instance-attribute

limit = limit if limit and limit > 0 else self.total

page_index property

page_index: int

The pageIndex for the current page.

If there is no pageIndex, returns -1.

page_info property

page_info: dict

The pageInfo for the current page.

page_size property

page_size: int

The pageSize for the current page.

If there is no pageSize, returns -1.

pages property

pages: list

A list of pages fetched.

total property

total: int

The total number of items (reported from the current page).

If there is no total, returns -1.

yielded instance-attribute

yielded = 0

__bool__

__bool__()
Source code in itkdb/responses.py
def __bool__(self):
    return bool(self.total)

__iter__

__iter__()
Source code in itkdb/responses.py
def __iter__(self):
    return self

__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