Skip to content

Commit e612347

Browse files
stainless-app[bot]stainless-bot
authored andcommitted
feat(api): OpenAPI spec update via Stainless API (#213)
1 parent c3f0e24 commit e612347

File tree

459 files changed

+5303
-464
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

459 files changed

+5303
-464
lines changed

api.md

+134-134
Large diffs are not rendered by default.

src/cloudflare/_streaming.py

+47-26
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class Stream(Generic[_T]):
2323

2424
response: httpx.Response
2525

26-
_decoder: SSEDecoder | SSEBytesDecoder
26+
_decoder: SSEBytesDecoder
2727

2828
def __init__(
2929
self,
@@ -46,10 +46,7 @@ def __iter__(self) -> Iterator[_T]:
4646
yield item
4747

4848
def _iter_events(self) -> Iterator[ServerSentEvent]:
49-
if isinstance(self._decoder, SSEBytesDecoder):
50-
yield from self._decoder.iter_bytes(self.response.iter_bytes())
51-
else:
52-
yield from self._decoder.iter(self.response.iter_lines())
49+
yield from self._decoder.iter_bytes(self.response.iter_bytes())
5350

5451
def __stream__(self) -> Iterator[_T]:
5552
cast_to = cast(Any, self._cast_to)
@@ -112,12 +109,8 @@ async def __aiter__(self) -> AsyncIterator[_T]:
112109
yield item
113110

114111
async def _iter_events(self) -> AsyncIterator[ServerSentEvent]:
115-
if isinstance(self._decoder, SSEBytesDecoder):
116-
async for sse in self._decoder.aiter_bytes(self.response.aiter_bytes()):
117-
yield sse
118-
else:
119-
async for sse in self._decoder.aiter(self.response.aiter_lines()):
120-
yield sse
112+
async for sse in self._decoder.aiter_bytes(self.response.aiter_bytes()):
113+
yield sse
121114

122115
async def __stream__(self) -> AsyncIterator[_T]:
123116
cast_to = cast(Any, self._cast_to)
@@ -205,21 +198,49 @@ def __init__(self) -> None:
205198
self._last_event_id = None
206199
self._retry = None
207200

208-
def iter(self, iterator: Iterator[str]) -> Iterator[ServerSentEvent]:
209-
"""Given an iterator that yields lines, iterate over it & yield every event encountered"""
210-
for line in iterator:
211-
line = line.rstrip("\n")
212-
sse = self.decode(line)
213-
if sse is not None:
214-
yield sse
215-
216-
async def aiter(self, iterator: AsyncIterator[str]) -> AsyncIterator[ServerSentEvent]:
217-
"""Given an async iterator that yields lines, iterate over it & yield every event encountered"""
218-
async for line in iterator:
219-
line = line.rstrip("\n")
220-
sse = self.decode(line)
221-
if sse is not None:
222-
yield sse
201+
def iter_bytes(self, iterator: Iterator[bytes]) -> Iterator[ServerSentEvent]:
202+
"""Given an iterator that yields raw binary data, iterate over it & yield every event encountered"""
203+
for chunk in self._iter_chunks(iterator):
204+
# Split before decoding so splitlines() only uses \r and \n
205+
for raw_line in chunk.splitlines():
206+
line = raw_line.decode("utf-8")
207+
sse = self.decode(line)
208+
if sse:
209+
yield sse
210+
211+
def _iter_chunks(self, iterator: Iterator[bytes]) -> Iterator[bytes]:
212+
"""Given an iterator that yields raw binary data, iterate over it and yield individual SSE chunks"""
213+
data = b""
214+
for chunk in iterator:
215+
for line in chunk.splitlines(keepends=True):
216+
data += line
217+
if data.endswith((b"\r\r", b"\n\n", b"\r\n\r\n")):
218+
yield data
219+
data = b""
220+
if data:
221+
yield data
222+
223+
async def aiter_bytes(self, iterator: AsyncIterator[bytes]) -> AsyncIterator[ServerSentEvent]:
224+
"""Given an iterator that yields raw binary data, iterate over it & yield every event encountered"""
225+
async for chunk in self._aiter_chunks(iterator):
226+
# Split before decoding so splitlines() only uses \r and \n
227+
for raw_line in chunk.splitlines():
228+
line = raw_line.decode("utf-8")
229+
sse = self.decode(line)
230+
if sse:
231+
yield sse
232+
233+
async def _aiter_chunks(self, iterator: AsyncIterator[bytes]) -> AsyncIterator[bytes]:
234+
"""Given an iterator that yields raw binary data, iterate over it and yield individual SSE chunks"""
235+
data = b""
236+
async for chunk in iterator:
237+
for line in chunk.splitlines(keepends=True):
238+
data += line
239+
if data.endswith((b"\r\r", b"\n\n", b"\r\n\r\n")):
240+
yield data
241+
data = b""
242+
if data:
243+
yield data
223244

224245
def decode(self, line: str) -> ServerSentEvent | None:
225246
# See: https://html.spec.whatwg.org/multipage/server-sent-events.html#event-stream-interpretation # noqa: E501

src/cloudflare/resources/accounts/accounts.py

+8
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ def list(
126126
self,
127127
*,
128128
direction: Literal["asc", "desc"] | NotGiven = NOT_GIVEN,
129+
name: str | NotGiven = NOT_GIVEN,
129130
page: float | NotGiven = NOT_GIVEN,
130131
per_page: float | NotGiven = NOT_GIVEN,
131132
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
@@ -141,6 +142,8 @@ def list(
141142
Args:
142143
direction: Direction to order results.
143144
145+
name: Name of the account.
146+
144147
page: Page number of paginated results.
145148
146149
per_page: Maximum number of results per page.
@@ -164,6 +167,7 @@ def list(
164167
query=maybe_transform(
165168
{
166169
"direction": direction,
170+
"name": name,
167171
"page": page,
168172
"per_page": per_page,
169173
},
@@ -288,6 +292,7 @@ def list(
288292
self,
289293
*,
290294
direction: Literal["asc", "desc"] | NotGiven = NOT_GIVEN,
295+
name: str | NotGiven = NOT_GIVEN,
291296
page: float | NotGiven = NOT_GIVEN,
292297
per_page: float | NotGiven = NOT_GIVEN,
293298
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
@@ -303,6 +308,8 @@ def list(
303308
Args:
304309
direction: Direction to order results.
305310
311+
name: Name of the account.
312+
306313
page: Page number of paginated results.
307314
308315
per_page: Maximum number of results per page.
@@ -326,6 +333,7 @@ def list(
326333
query=maybe_transform(
327334
{
328335
"direction": direction,
336+
"name": name,
329337
"page": page,
330338
"per_page": per_page,
331339
},

src/cloudflare/resources/accounts/members.py

+5
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
MemberDeleteResponse,
3535
member_list_params,
3636
member_create_params,
37+
member_delete_params,
3738
member_update_params,
3839
)
3940

@@ -208,6 +209,7 @@ def delete(
208209
member_id: str,
209210
*,
210211
account_id: object,
212+
body: object,
211213
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
212214
# The extra values given here take precedence over values defined on the client or passed to this method.
213215
extra_headers: Headers | None = None,
@@ -233,6 +235,7 @@ def delete(
233235
raise ValueError(f"Expected a non-empty value for `member_id` but received {member_id!r}")
234236
return self._delete(
235237
f"/accounts/{account_id}/members/{member_id}",
238+
body=maybe_transform(body, member_delete_params.MemberDeleteParams),
236239
options=make_request_options(
237240
extra_headers=extra_headers,
238241
extra_query=extra_query,
@@ -452,6 +455,7 @@ async def delete(
452455
member_id: str,
453456
*,
454457
account_id: object,
458+
body: object,
455459
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
456460
# The extra values given here take precedence over values defined on the client or passed to this method.
457461
extra_headers: Headers | None = None,
@@ -477,6 +481,7 @@ async def delete(
477481
raise ValueError(f"Expected a non-empty value for `member_id` but received {member_id!r}")
478482
return await self._delete(
479483
f"/accounts/{account_id}/members/{member_id}",
484+
body=await async_maybe_transform(body, member_delete_params.MemberDeleteParams),
480485
options=make_request_options(
481486
extra_headers=extra_headers,
482487
extra_query=extra_query,

src/cloudflare/resources/addressing/address_maps/accounts.py

+18-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
import httpx
88

99
from ...._types import NOT_GIVEN, Body, Query, Headers, NotGiven
10+
from ...._utils import (
11+
maybe_transform,
12+
async_maybe_transform,
13+
)
1014
from ...._compat import cached_property
1115
from ...._resource import SyncAPIResource, AsyncAPIResource
1216
from ...._response import (
@@ -19,7 +23,12 @@
1923
from ...._base_client import (
2024
make_request_options,
2125
)
22-
from ....types.addressing.address_maps import AccountDeleteResponse, AccountUpdateResponse
26+
from ....types.addressing.address_maps import (
27+
AccountDeleteResponse,
28+
AccountUpdateResponse,
29+
account_delete_params,
30+
account_update_params,
31+
)
2332

2433
__all__ = ["Accounts", "AsyncAccounts"]
2534

@@ -38,6 +47,7 @@ def update(
3847
address_map_id: str,
3948
*,
4049
account_id: str,
50+
body: object,
4151
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
4252
# The extra values given here take precedence over values defined on the client or passed to this method.
4353
extra_headers: Headers | None = None,
@@ -69,6 +79,7 @@ def update(
6979
Optional[AccountUpdateResponse],
7080
self._put(
7181
f"/accounts/{account_id}/addressing/address_maps/{address_map_id}/accounts/{account_id}",
82+
body=maybe_transform(body, account_update_params.AccountUpdateParams),
7283
options=make_request_options(
7384
extra_headers=extra_headers,
7485
extra_query=extra_query,
@@ -87,6 +98,7 @@ def delete(
8798
address_map_id: str,
8899
*,
89100
account_id: str,
101+
body: object,
90102
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
91103
# The extra values given here take precedence over values defined on the client or passed to this method.
92104
extra_headers: Headers | None = None,
@@ -118,6 +130,7 @@ def delete(
118130
Optional[AccountDeleteResponse],
119131
self._delete(
120132
f"/accounts/{account_id}/addressing/address_maps/{address_map_id}/accounts/{account_id}",
133+
body=maybe_transform(body, account_delete_params.AccountDeleteParams),
121134
options=make_request_options(
122135
extra_headers=extra_headers,
123136
extra_query=extra_query,
@@ -146,6 +159,7 @@ async def update(
146159
address_map_id: str,
147160
*,
148161
account_id: str,
162+
body: object,
149163
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
150164
# The extra values given here take precedence over values defined on the client or passed to this method.
151165
extra_headers: Headers | None = None,
@@ -177,6 +191,7 @@ async def update(
177191
Optional[AccountUpdateResponse],
178192
await self._put(
179193
f"/accounts/{account_id}/addressing/address_maps/{address_map_id}/accounts/{account_id}",
194+
body=await async_maybe_transform(body, account_update_params.AccountUpdateParams),
180195
options=make_request_options(
181196
extra_headers=extra_headers,
182197
extra_query=extra_query,
@@ -195,6 +210,7 @@ async def delete(
195210
address_map_id: str,
196211
*,
197212
account_id: str,
213+
body: object,
198214
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
199215
# The extra values given here take precedence over values defined on the client or passed to this method.
200216
extra_headers: Headers | None = None,
@@ -226,6 +242,7 @@ async def delete(
226242
Optional[AccountDeleteResponse],
227243
await self._delete(
228244
f"/accounts/{account_id}/addressing/address_maps/{address_map_id}/accounts/{account_id}",
245+
body=await async_maybe_transform(body, account_delete_params.AccountDeleteParams),
229246
options=make_request_options(
230247
extra_headers=extra_headers,
231248
extra_query=extra_query,

src/cloudflare/resources/addressing/address_maps/address_maps.py

+5
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
AddressMapDeleteResponse,
5757
address_map_edit_params,
5858
address_map_create_params,
59+
address_map_delete_params,
5960
)
6061

6162
__all__ = ["AddressMaps", "AsyncAddressMaps"]
@@ -177,6 +178,7 @@ def delete(
177178
address_map_id: str,
178179
*,
179180
account_id: str,
181+
body: object,
180182
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
181183
# The extra values given here take precedence over values defined on the client or passed to this method.
182184
extra_headers: Headers | None = None,
@@ -210,6 +212,7 @@ def delete(
210212
Optional[AddressMapDeleteResponse],
211213
self._delete(
212214
f"/accounts/{account_id}/addressing/address_maps/{address_map_id}",
215+
body=maybe_transform(body, address_map_delete_params.AddressMapDeleteParams),
213216
options=make_request_options(
214217
extra_headers=extra_headers,
215218
extra_query=extra_query,
@@ -451,6 +454,7 @@ async def delete(
451454
address_map_id: str,
452455
*,
453456
account_id: str,
457+
body: object,
454458
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
455459
# The extra values given here take precedence over values defined on the client or passed to this method.
456460
extra_headers: Headers | None = None,
@@ -484,6 +488,7 @@ async def delete(
484488
Optional[AddressMapDeleteResponse],
485489
await self._delete(
486490
f"/accounts/{account_id}/addressing/address_maps/{address_map_id}",
491+
body=await async_maybe_transform(body, address_map_delete_params.AddressMapDeleteParams),
487492
options=make_request_options(
488493
extra_headers=extra_headers,
489494
extra_query=extra_query,

0 commit comments

Comments
 (0)