Skip to content

Commit 0d020c3

Browse files
Merge pull request #148 from stainless-sdks/robert/fix-multipart
1 parent 6185ace commit 0d020c3

5 files changed

Lines changed: 28 additions & 31 deletions

File tree

examples/workers/script_upload.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -71,20 +71,20 @@ def main() -> None:
7171
}
7272
],
7373
},
74-
files={
74+
files=[
7575
# Add main_module file
76-
script_file_name: (
76+
(
7777
script_file_name,
7878
bytes(script_content, "utf-8"),
7979
"application/javascript+module",
80-
)
80+
),
8181
# Can add other files, such as more modules or source maps
82-
# source_map_file_name: (
83-
# source_map_file_name,
84-
# bytes(source_map_content, "utf-8"),
85-
# "application/source-map"
86-
#)
87-
},
82+
# (
83+
# source_map_file_name,
84+
# bytes(source_map_content, "utf-8"),
85+
# "application/source-map",
86+
# ),
87+
],
8888
)
8989
print("Script Upload success!")
9090
print(script.to_json(indent=2))

src/cloudflare/resources/kv/namespaces/values.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ def update(
137137
},
138138
value_update_params.ValueUpdateParams,
139139
),
140+
multipart_syntax="json",
140141
post_parser=ResultWrapper[Optional[ValueUpdateResponse]]._unwrapper,
141142
),
142143
cast_to=cast(Type[Optional[ValueUpdateResponse]], ResultWrapper[ValueUpdateResponse]),
@@ -351,6 +352,7 @@ async def update(
351352
},
352353
value_update_params.ValueUpdateParams,
353354
),
355+
multipart_syntax="json",
354356
post_parser=ResultWrapper[Optional[ValueUpdateResponse]]._unwrapper,
355357
),
356358
cast_to=cast(Type[Optional[ValueUpdateResponse]], ResultWrapper[ValueUpdateResponse]),

src/cloudflare/resources/workers/scripts/scripts.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from __future__ import annotations
44

5-
from typing import List, Type, Mapping, Optional, cast
5+
from typing import List, Type, Optional, cast
66

77
import httpx
88

@@ -47,7 +47,7 @@
4747
AsyncVersionsResourceWithStreamingResponse,
4848
)
4949
from ...._types import NOT_GIVEN, Body, Query, Headers, NotGiven, FileTypes
50-
from ...._utils import extract_files, maybe_transform, deepcopy_minimal, async_maybe_transform
50+
from ...._utils import is_given, maybe_transform, deepcopy_minimal, async_maybe_transform
5151
from .schedules import (
5252
SchedulesResource,
5353
AsyncSchedulesResource,
@@ -216,10 +216,9 @@ def update(
216216
body = deepcopy_minimal(
217217
{
218218
"metadata": metadata,
219-
"files": files,
220219
}
221220
)
222-
extracted_files = extract_files(cast(Mapping[str, object], body), paths=[["files", "<array>"]])
221+
extracted_files = [("files", file) for file in files] if is_given(files) else []
223222
if extracted_files:
224223
# It should be noted that the actual Content-Type header that will be
225224
# sent to the server will contain a `boundary` parameter, e.g.
@@ -234,7 +233,7 @@ def update(
234233
extra_query=extra_query,
235234
extra_body=extra_body,
236235
timeout=timeout,
237-
multipart_syntax='json',
236+
multipart_syntax="json",
238237
post_parser=ResultWrapper[ScriptUpdateResponse]._unwrapper,
239238
),
240239
cast_to=cast(Type[ScriptUpdateResponse], ResultWrapper[ScriptUpdateResponse]),
@@ -489,10 +488,9 @@ async def update(
489488
body = deepcopy_minimal(
490489
{
491490
"metadata": metadata,
492-
"files": files,
493491
}
494492
)
495-
extracted_files = extract_files(cast(Mapping[str, object], body), paths=[["files", "<array>"]])
493+
extracted_files = [("files", file) for file in files] if is_given(files) else []
496494
if extracted_files:
497495
# It should be noted that the actual Content-Type header that will be
498496
# sent to the server will contain a `boundary` parameter, e.g.
@@ -508,7 +506,7 @@ async def update(
508506
extra_body=extra_body,
509507
timeout=timeout,
510508
post_parser=ResultWrapper[ScriptUpdateResponse]._unwrapper,
511-
multipart_syntax='json',
509+
multipart_syntax="json",
512510
),
513511
cast_to=cast(Type[ScriptUpdateResponse], ResultWrapper[ScriptUpdateResponse]),
514512
)

src/cloudflare/resources/workers/scripts/versions.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22

33
from __future__ import annotations
44

5-
from typing import List, Type, Mapping, cast
5+
from typing import List, Type, cast
66

77
import httpx
88

99
from ...._types import NOT_GIVEN, Body, Query, Headers, NotGiven, FileTypes
10-
from ...._utils import extract_files, maybe_transform, deepcopy_minimal, async_maybe_transform
10+
from ...._utils import is_given, maybe_transform, deepcopy_minimal, async_maybe_transform
1111
from ...._compat import cached_property
1212
from ...._resource import SyncAPIResource, AsyncAPIResource
1313
from ...._response import (
@@ -97,10 +97,10 @@ def create(
9797
body = deepcopy_minimal(
9898
{
9999
"metadata": metadata,
100-
"files": files,
101100
}
102101
)
103-
extracted_files = extract_files(cast(Mapping[str, object], body), paths=[["files", "<array>"]])
102+
extracted_files = [("files", file) for file in files] if is_given(files) else []
103+
104104
# It should be noted that the actual Content-Type header that will be
105105
# sent to the server will contain a `boundary` parameter, e.g.
106106
# multipart/form-data; boundary=---abc--
@@ -299,10 +299,9 @@ async def create(
299299
body = deepcopy_minimal(
300300
{
301301
"metadata": metadata,
302-
"files": files,
303302
}
304303
)
305-
extracted_files = extract_files(cast(Mapping[str, object], body), paths=[["files", "<array>"]])
304+
extracted_files = [("files", file) for file in files] if is_given(files) else []
306305
# It should be noted that the actual Content-Type header that will be
307306
# sent to the server will contain a `boundary` parameter, e.g.
308307
# multipart/form-data; boundary=---abc--

src/cloudflare/resources/workers_for_platforms/dispatch/namespaces/scripts/scripts.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from __future__ import annotations
44

5-
from typing import List, Type, Mapping, Optional, cast
5+
from typing import List, Type, Optional, cast
66

77
import httpx
88

@@ -47,7 +47,7 @@
4747
AsyncSettingsResourceWithStreamingResponse,
4848
)
4949
from ......_types import NOT_GIVEN, Body, Query, Headers, NotGiven, FileTypes
50-
from ......_utils import extract_files, maybe_transform, deepcopy_minimal, async_maybe_transform
50+
from ......_utils import is_given, maybe_transform, deepcopy_minimal, async_maybe_transform
5151
from ......_compat import cached_property
5252
from .asset_upload import (
5353
AssetUploadResource,
@@ -172,10 +172,9 @@ def update(
172172
body = deepcopy_minimal(
173173
{
174174
"metadata": metadata,
175-
"files": files,
176175
}
177176
)
178-
extracted_files = extract_files(cast(Mapping[str, object], body), paths=[["files", "<array>"]])
177+
extracted_files = [("files", file) for file in files] if is_given(files) else []
179178
if extracted_files:
180179
# It should be noted that the actual Content-Type header that will be
181180
# sent to the server will contain a `boundary` parameter, e.g.
@@ -190,7 +189,7 @@ def update(
190189
extra_query=extra_query,
191190
extra_body=extra_body,
192191
timeout=timeout,
193-
multipart_syntax='json',
192+
multipart_syntax="json",
194193
post_parser=ResultWrapper[ScriptUpdateResponse]._unwrapper,
195194
),
196195
cast_to=cast(Type[ScriptUpdateResponse], ResultWrapper[ScriptUpdateResponse]),
@@ -402,10 +401,9 @@ async def update(
402401
body = deepcopy_minimal(
403402
{
404403
"metadata": metadata,
405-
"files": files,
406404
}
407405
)
408-
extracted_files = extract_files(cast(Mapping[str, object], body), paths=[["files", "<array>"]])
406+
extracted_files = [("files", file) for file in files] if is_given(files) else []
409407
if extracted_files:
410408
# It should be noted that the actual Content-Type header that will be
411409
# sent to the server will contain a `boundary` parameter, e.g.
@@ -420,7 +418,7 @@ async def update(
420418
extra_query=extra_query,
421419
extra_body=extra_body,
422420
timeout=timeout,
423-
multipart_syntax='json',
421+
multipart_syntax="json",
424422
post_parser=ResultWrapper[ScriptUpdateResponse]._unwrapper,
425423
),
426424
cast_to=cast(Type[ScriptUpdateResponse], ResultWrapper[ScriptUpdateResponse]),

0 commit comments

Comments
 (0)