|
2 | 2 |
|
3 | 3 | import json |
4 | 4 | from http import HTTPMethod, HTTPStatus |
5 | | -from typing import Any |
6 | 5 |
|
7 | 6 | from beartype import BeartypeConf, beartype |
| 7 | +from urllib3.fields import RequestField |
8 | 8 | from urllib3.filepost import encode_multipart_formdata |
9 | 9 | from vws_auth_tools import authorization_header, rfc_1123_date |
10 | 10 |
|
@@ -112,15 +112,30 @@ def query( |
112 | 112 | An ordered list of target details of matching targets. |
113 | 113 | """ |
114 | 114 | 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"), |
122 | 135 | ), |
123 | | - } |
| 136 | + max_num_results_field, |
| 137 | + include_target_data_field, |
| 138 | + ] |
124 | 139 | date = rfc_1123_date() |
125 | 140 | request_path = "/v1/query" |
126 | 141 | content, content_type_header = encode_multipart_formdata(fields=body) |
|
0 commit comments