Skip to content

Commit b0437fd

Browse files
committed
Type Cloud Reco multipart fields
1 parent 200baeb commit b0437fd

2 files changed

Lines changed: 53 additions & 26 deletions

File tree

src/vws/async_query.py

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@
44

55
import json
66
from http import HTTPMethod, HTTPStatus
7-
from typing import Any, Self
7+
from typing import Self
88

99
from beartype import BeartypeConf, beartype
10+
from urllib3.fields import RequestField
1011
from urllib3.filepost import encode_multipart_formdata
1112
from vws_auth_tools import authorization_header, rfc_1123_date
1213

@@ -131,23 +132,34 @@ async def query(
131132
targets.
132133
"""
133134
image_content = _get_image_data(image=image)
134-
body: dict[str, Any] = { # pyrefly: ignore [explicit-any]
135-
"image": (
136-
"image.jpeg",
137-
image_content,
138-
"image/jpeg",
139-
),
140-
"max_num_results": (
141-
None,
142-
max_num_results,
143-
"text/plain",
144-
),
145-
"include_target_data": (
146-
None,
147-
include_target_data.value,
148-
"text/plain",
135+
max_num_results_field = RequestField(
136+
name="max_num_results",
137+
data=str(object=max_num_results),
138+
)
139+
max_num_results_field.make_multipart(
140+
content_disposition="form-data",
141+
content_type="text/plain",
142+
)
143+
include_target_data_field = RequestField(
144+
name="include_target_data",
145+
data=include_target_data.value,
146+
)
147+
include_target_data_field.make_multipart(
148+
content_disposition="form-data",
149+
content_type="text/plain",
150+
)
151+
body = [
152+
RequestField.from_tuples(
153+
fieldname="image",
154+
value=(
155+
"image.jpeg",
156+
image_content,
157+
"image/jpeg",
158+
),
149159
),
150-
}
160+
max_num_results_field,
161+
include_target_data_field,
162+
]
151163
date = rfc_1123_date()
152164
request_path = "/v1/query"
153165
content, content_type_header = encode_multipart_formdata(fields=body)

src/vws/query.py

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
import json
44
from http import HTTPMethod, HTTPStatus
5-
from typing import Any
65

76
from beartype import BeartypeConf, beartype
7+
from urllib3.fields import RequestField
88
from urllib3.filepost import encode_multipart_formdata
99
from vws_auth_tools import authorization_header, rfc_1123_date
1010

@@ -112,15 +112,30 @@ def query(
112112
An ordered list of target details of matching targets.
113113
"""
114114
image_content = _get_image_data(image=image)
115-
body: dict[str, Any] = { # pyrefly: ignore [explicit-any]
116-
"image": ("image.jpeg", image_content, "image/jpeg"),
117-
"max_num_results": (None, max_num_results, "text/plain"),
118-
"include_target_data": (
119-
None,
120-
include_target_data.value,
121-
"text/plain",
115+
max_num_results_field = RequestField(
116+
name="max_num_results",
117+
data=str(object=max_num_results),
118+
)
119+
max_num_results_field.make_multipart(
120+
content_disposition="form-data",
121+
content_type="text/plain",
122+
)
123+
include_target_data_field = RequestField(
124+
name="include_target_data",
125+
data=include_target_data.value,
126+
)
127+
include_target_data_field.make_multipart(
128+
content_disposition="form-data",
129+
content_type="text/plain",
130+
)
131+
body = [
132+
RequestField.from_tuples(
133+
fieldname="image",
134+
value=("image.jpeg", image_content, "image/jpeg"),
122135
),
123-
}
136+
max_num_results_field,
137+
include_target_data_field,
138+
]
124139
date = rfc_1123_date()
125140
request_path = "/v1/query"
126141
content, content_type_header = encode_multipart_formdata(fields=body)

0 commit comments

Comments
 (0)