-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathpagination.py
More file actions
85 lines (64 loc) · 2.48 KB
/
pagination.py
File metadata and controls
85 lines (64 loc) · 2.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
from typing import List, Generic, TypeVar, Optional
from typing_extensions import override
from ._models import BaseModel
from ._base_client import BasePage, PageInfo, BaseSyncPage, BaseAsyncPage
__all__ = ["RunsCursorPagePageInfo", "SyncRunsCursorPage", "AsyncRunsCursorPage"]
_T = TypeVar("_T")
class RunsCursorPagePageInfo(BaseModel):
has_next_page: Optional[bool] = None
next_cursor: Optional[str] = None
class SyncRunsCursorPage(BaseSyncPage[_T], BasePage[_T], Generic[_T]):
runs: List[_T]
page_info: Optional[RunsCursorPagePageInfo] = None
@override
def _get_page_items(self) -> List[_T]:
runs = self.runs
if not runs:
return []
return runs
@override
def has_next_page(self) -> bool:
has_next_page = None
if self.page_info is not None:
if self.page_info.has_next_page is not None:
has_next_page = self.page_info.has_next_page
if has_next_page is not None and has_next_page is False:
return False
return super().has_next_page()
@override
def next_page_info(self) -> Optional[PageInfo]:
next_cursor = None
if self.page_info is not None:
if self.page_info.next_cursor is not None:
next_cursor = self.page_info.next_cursor
if not next_cursor:
return None
return PageInfo(params={"cursor": next_cursor})
class AsyncRunsCursorPage(BaseAsyncPage[_T], BasePage[_T], Generic[_T]):
runs: List[_T]
page_info: Optional[RunsCursorPagePageInfo] = None
@override
def _get_page_items(self) -> List[_T]:
runs = self.runs
if not runs:
return []
return runs
@override
def has_next_page(self) -> bool:
has_next_page = None
if self.page_info is not None:
if self.page_info.has_next_page is not None:
has_next_page = self.page_info.has_next_page
if has_next_page is not None and has_next_page is False:
return False
return super().has_next_page()
@override
def next_page_info(self) -> Optional[PageInfo]:
next_cursor = None
if self.page_info is not None:
if self.page_info.next_cursor is not None:
next_cursor = self.page_info.next_cursor
if not next_cursor:
return None
return PageInfo(params={"cursor": next_cursor})