MCPcopy Index your code
hub / github.com/PyGithub/PyGithub / _getPage

Method _getPage

github/PaginatedList.py:393–441  ·  view source on GitHub ↗
(self, data: Any, headers: dict[str, str | int] | None)

Source from the content-addressed store, hash-verified

391 return self._getPage(pagination, {})
392
393 def _getPage(self, data: Any, headers: dict[str, str | int] | None) -> list[T]:
394 if self.is_rest:
395 self.__nextUrl = None # type: ignore
396 if len(data) > 0:
397 links = self.__parseLinkHeader(headers) # type: ignore
398 if self._reversed:
399 if "prev" in links:
400 self.__nextUrl = links["prev"]
401 elif "next" in links:
402 self.__nextUrl = links["next"]
403 if "last" in links:
404 self.__lastUrl = links["last"]
405 self.__nextParams = {}
406 if self.__list_item in data:
407 self.__totalCount = data.get(self.__total_count_item)
408 data = data[self.__list_item]
409 content = [
410 self.__contentClass(self.__requester, headers, self._transformAttributes(element)) # type: ignore
411 for element in data
412 if element is not None
413 ]
414 if self._reversed:
415 return content[::-1]
416 return content
417 else:
418 if "pageInfo" not in data:
419 raise RuntimeError(f"Query must provide pagination with pageInfo:\n{self.__graphql_query}")
420
421 self.__page_info = data["pageInfo"]
422 if any(
423 item not in self.__page_info # type: ignore
424 for item in ["startCursor", "endCursor", "hasNextPage", "hasPreviousPage"]
425 ):
426 raise RuntimeError(f"Query must provide pagination with pageInfo\n{self.__graphql_query}")
427
428 if self.__totalCount is None:
429 if "totalCount" not in data:
430 raise RuntimeError(f"Query must provide totalCount\n{self.__graphql_query}")
431 self.__totalCount = data["totalCount"]
432
433 if "nodes" not in data:
434 raise RuntimeError(
435 f"No nodes found under pagination path {self.__list_item}: {self.paths_of_dict(data)}"
436 )
437
438 nodes = data["nodes"]
439 if self._reversed:
440 nodes = nodes[::-1]
441 return [self.__contentClass(self.__requester, {}, element) for element in nodes if element is not None]
442
443 def __parseLinkHeader(self, headers: dict[str, str | int]) -> dict[str, str]:
444 links = {}

Callers 2

__init__Method · 0.95
_fetchNextPageMethod · 0.95

Calls 4

__parseLinkHeaderMethod · 0.95
_transformAttributesMethod · 0.95
paths_of_dictMethod · 0.95
getMethod · 0.80

Tested by

no test coverage detected