| 186 | |
| 187 | # v3: move * before firstUrl and fix call sites |
| 188 | def __init__( |
| 189 | self, |
| 190 | contentClass: type[T], |
| 191 | requester: Requester, |
| 192 | firstUrl: str | None = None, |
| 193 | firstParams: dict[str, Any] | None = None, |
| 194 | *, |
| 195 | headers: dict[str, str] | None = None, |
| 196 | list_item: str | list[str] = "items", |
| 197 | total_count_item: str = "total_count", |
| 198 | firstData: Any | None = None, |
| 199 | firstHeaders: dict[str, str | int] | None = None, |
| 200 | attributesTransformer: Callable[[dict[str, Any]], dict[str, Any]] | None = None, |
| 201 | graphql_query: str | None = None, |
| 202 | graphql_variables: dict[str, Any] | None = None, |
| 203 | ): |
| 204 | if firstUrl is None and firstData is None and graphql_query is None: |
| 205 | raise ValueError("Either firstUrl or graphql_query must be given") |
| 206 | if firstUrl is not None and graphql_query is not None: |
| 207 | raise ValueError("Only one of firstUrl or graphql_query can be given") |
| 208 | if graphql_query is not None: |
| 209 | if not (isinstance(list_item, list) and all(isinstance(item, str) for item in list_item)): |
| 210 | raise ValueError("With graphql_query given, item_list must be a list of strings") |
| 211 | |
| 212 | firstParams = firstParams or {} |
| 213 | |
| 214 | # we add the per_page parameter if that value is not the default |
| 215 | # but only if there is no per_page parameter in the firstParams |
| 216 | if "per_page" not in firstParams and requester.per_page != Consts.DEFAULT_PER_PAGE: |
| 217 | firstParams["per_page"] = requester.per_page |
| 218 | |
| 219 | self.__requester = requester |
| 220 | self.__contentClass = contentClass |
| 221 | |
| 222 | self.__is_rest = firstUrl is not None or firstData is not None |
| 223 | self.__firstUrl = firstUrl |
| 224 | self.__firstParams: dict[str, Any] = firstParams |
| 225 | self.__firstData = firstData |
| 226 | self.__firstHeaders = firstHeaders |
| 227 | self.__nextUrl = firstUrl |
| 228 | self.__nextParams: dict[str, Any] = firstParams |
| 229 | self.__lastUrl: str | None = None |
| 230 | self.__headers = headers |
| 231 | self.__list_item = list_item |
| 232 | self.__total_count_item = total_count_item |
| 233 | |
| 234 | self._reversed = False |
| 235 | self.__totalCount: int | None = None |
| 236 | self._attributesTransformer = attributesTransformer |
| 237 | |
| 238 | self.__graphql_query = graphql_query |
| 239 | self.__graphql_variables = graphql_variables or {} |
| 240 | self.__page_info = None |
| 241 | |
| 242 | first_page = [] |
| 243 | if firstData is not None: |
| 244 | first_page = self._getPage(firstData, firstHeaders) |
| 245 | # this paginated list contains a single page |