Skip to content

Commit 26812a8

Browse files
stainless-app[bot]stainless-bot
authored andcommitted
feat: update via SDK Studio (#119)
1 parent 4063a86 commit 26812a8

File tree

1 file changed

+64
-1
lines changed

1 file changed

+64
-1
lines changed

src/cloudflare/pagination.py

+64-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
# File generated from our OpenAPI spec by Stainless.
22

3-
from typing import List, Generic, TypeVar, Optional, cast
3+
from typing import Any, List, Type, Generic, Mapping, TypeVar, Optional, cast
44
from typing_extensions import override
55

6+
from httpx import Response
7+
8+
from ._utils import is_mapping
69
from ._models import BaseModel, GenericModel
710
from ._base_client import BasePage, PageInfo, BaseSyncPage, BaseAsyncPage
811

@@ -20,8 +23,12 @@
2023
"CursorLimitPaginationResultInfo",
2124
"SyncCursorLimitPagination",
2225
"AsyncCursorLimitPagination",
26+
"SyncSinglePage",
27+
"AsyncSinglePage",
2328
]
2429

30+
_BaseModelT = TypeVar("_BaseModelT", bound=BaseModel)
31+
2532
_T = TypeVar("_T")
2633

2734

@@ -247,3 +254,59 @@ def next_page_info(self) -> Optional[PageInfo]:
247254
return None
248255

249256
return PageInfo(params={"cursor": cursor})
257+
258+
259+
class SyncSinglePage(BaseSyncPage[_T], BasePage[_T], Generic[_T]):
260+
items: List[_T]
261+
262+
@override
263+
def _get_page_items(self) -> List[_T]:
264+
items = self.items
265+
if not items:
266+
return []
267+
return items
268+
269+
@override
270+
def next_page_info(self) -> None:
271+
"""
272+
This page represents a response that isn't actually paginated at the API level
273+
so there will never be a next page.
274+
"""
275+
return None
276+
277+
@classmethod
278+
def build(cls: Type[_BaseModelT], *, response: Response, data: object) -> _BaseModelT: # noqa: ARG003
279+
return cls.construct(
280+
None,
281+
**{
282+
**(cast(Mapping[str, Any], data) if is_mapping(data) else {"items": data}),
283+
},
284+
)
285+
286+
287+
class AsyncSinglePage(BaseAsyncPage[_T], BasePage[_T], Generic[_T]):
288+
items: List[_T]
289+
290+
@override
291+
def _get_page_items(self) -> List[_T]:
292+
items = self.items
293+
if not items:
294+
return []
295+
return items
296+
297+
@override
298+
def next_page_info(self) -> None:
299+
"""
300+
This page represents a response that isn't actually paginated at the API level
301+
so there will never be a next page.
302+
"""
303+
return None
304+
305+
@classmethod
306+
def build(cls: Type[_BaseModelT], *, response: Response, data: object) -> _BaseModelT: # noqa: ARG003
307+
return cls.construct(
308+
None,
309+
**{
310+
**(cast(Mapping[str, Any], data) if is_mapping(data) else {"items": data}),
311+
},
312+
)

0 commit comments

Comments
 (0)