Skip to content

Commit

Permalink
feat: update via SDK Studio (#119)
Browse files Browse the repository at this point in the history
  • Loading branch information
stainless-app[bot] authored and stainless-bot committed Mar 12, 2024
1 parent 4063a86 commit 26812a8
Showing 1 changed file with 64 additions and 1 deletion.
65 changes: 64 additions & 1 deletion src/cloudflare/pagination.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
# File generated from our OpenAPI spec by Stainless.

from typing import List, Generic, TypeVar, Optional, cast
from typing import Any, List, Type, Generic, Mapping, TypeVar, Optional, cast
from typing_extensions import override

from httpx import Response

from ._utils import is_mapping
from ._models import BaseModel, GenericModel
from ._base_client import BasePage, PageInfo, BaseSyncPage, BaseAsyncPage

Expand All @@ -20,8 +23,12 @@
"CursorLimitPaginationResultInfo",
"SyncCursorLimitPagination",
"AsyncCursorLimitPagination",
"SyncSinglePage",
"AsyncSinglePage",
]

_BaseModelT = TypeVar("_BaseModelT", bound=BaseModel)

_T = TypeVar("_T")


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

return PageInfo(params={"cursor": cursor})


class SyncSinglePage(BaseSyncPage[_T], BasePage[_T], Generic[_T]):
items: List[_T]

@override
def _get_page_items(self) -> List[_T]:
items = self.items
if not items:
return []
return items

@override
def next_page_info(self) -> None:
"""
This page represents a response that isn't actually paginated at the API level
so there will never be a next page.
"""
return None

@classmethod
def build(cls: Type[_BaseModelT], *, response: Response, data: object) -> _BaseModelT: # noqa: ARG003
return cls.construct(
None,
**{
**(cast(Mapping[str, Any], data) if is_mapping(data) else {"items": data}),
},
)


class AsyncSinglePage(BaseAsyncPage[_T], BasePage[_T], Generic[_T]):
items: List[_T]

@override
def _get_page_items(self) -> List[_T]:
items = self.items
if not items:
return []
return items

@override
def next_page_info(self) -> None:
"""
This page represents a response that isn't actually paginated at the API level
so there will never be a next page.
"""
return None

@classmethod
def build(cls: Type[_BaseModelT], *, response: Response, data: object) -> _BaseModelT: # noqa: ARG003
return cls.construct(
None,
**{
**(cast(Mapping[str, Any], data) if is_mapping(data) else {"items": data}),
},
)

0 comments on commit 26812a8

Please sign in to comment.