def _get_paged_items_list()

in analytics/circleci_analyze.py [0:0]


    def _get_paged_items_list(self, url: str, params: Optional[Dict] = None, item_count: Optional[int] = -1) -> List:
        rc, token, run_once = [], None, False

        def _should_quit():
            nonlocal run_once, rc, token
            if not run_once:
                run_once = True
                return False
            if token is None:
                return True
            if item_count is None:
                return True
            return item_count >= 0 and len(rc) >= item_count

        if params is None:
            params = {}
        while not _should_quit():
            if token is not None:
                params['page-token'] = token
            r = self.session.get(url, params=params, headers=self.headers)
            try:
                j = r.json()
            except json.JSONDecodeError:
                print(f"Failed to decode {rc}", file=sys.stderr)
                raise
            if 'message' in j:
                raise RuntimeError(f'Failed to get list from {url}: {j["message"]}')
            token = j['next_page_token']
            rc.extend(j['items'])
        return rc