-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathgeneral.py
270 lines (244 loc) · 11.1 KB
/
general.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
from unstructured_client._hooks.custom.clean_server_url_hook import clean_server_url
from .basesdk import BaseSDK
from enum import Enum
from typing import Any, Dict, List, Mapping, Optional, Union, cast
from unstructured_client import utils
from unstructured_client._hooks import HookContext
from unstructured_client.models import errors, operations, shared
from unstructured_client.types import BaseModel, OptionalNullable, UNSET
from unstructured_client.sdkconfiguration import SERVER_PLATFORM_API, SERVERS
class PartitionAcceptEnum(str, Enum):
APPLICATION_JSON = "application/json"
TEXT_CSV = "text/csv"
class General(BaseSDK):
def get_default_server_url(self) -> str:
client_url, *_ = self.sdk_configuration.get_server_details()
if client_url == SERVERS[SERVER_PLATFORM_API].rstrip("/"):
#Note(yuming):get_server_details will set the default server to platform-api
return operations.PARTITION_SERVERS[
operations.PARTITION_SERVER_SAAS_API
].rstrip("/")
return clean_server_url(client_url)
def partition(
self,
*,
request: Union[
operations.PartitionRequest, operations.PartitionRequestTypedDict
],
retries: OptionalNullable[utils.RetryConfig] = UNSET,
server_url: Optional[str] = None,
timeout_ms: Optional[int] = None,
accept_header_override: Optional[PartitionAcceptEnum] = None,
http_headers: Optional[Mapping[str, str]] = None,
) -> operations.PartitionResponse:
r"""Summary
Description
:param request: The request object to send.
:param retries: Override the default retry configuration for this method
:param server_url: Override the default server URL for this method
:param timeout_ms: Override the default request timeout configuration for this method in milliseconds
:param accept_header_override: Override the default accept header for this method
:param http_headers: Additional headers to set or replace on requests.
"""
base_url = clean_server_url(server_url) if server_url is not None else self.get_default_server_url()
url_variables = None
if timeout_ms is None:
timeout_ms = self.sdk_configuration.timeout_ms
if not isinstance(request, BaseModel):
request = utils.unmarshal(request, operations.PartitionRequest)
request = cast(operations.PartitionRequest, request)
req = self._build_request(
method="POST",
path="/general/v0/general",
base_url=base_url,
url_variables=url_variables,
request=request,
request_body_required=True,
request_has_path_params=False,
request_has_query_params=True,
user_agent_header="user-agent",
accept_header_value=accept_header_override.value
if accept_header_override is not None
else "application/json;q=1, text/csv;q=0",
http_headers=http_headers,
security=self.sdk_configuration.security,
get_serialized_body=lambda: utils.serialize_request_body(
request.partition_parameters,
False,
False,
"multipart",
shared.PartitionParameters,
),
timeout_ms=timeout_ms,
)
if retries == UNSET:
if self.sdk_configuration.retry_config is not UNSET:
retries = self.sdk_configuration.retry_config
else:
retries = utils.RetryConfig(
"backoff", utils.BackoffStrategy(3000, 720000, 1.88, 1800000), True
)
retry_config = None
if isinstance(retries, utils.RetryConfig):
retry_config = (retries, ["5xx"])
http_res = self.do_request(
hook_ctx=HookContext(
base_url=base_url or "",
operation_id="partition",
oauth2_scopes=[],
security_source=self.sdk_configuration.security,
),
request=req,
error_status_codes=["422", "4XX", "5XX"],
retry_config=retry_config,
)
response_data: Any = None
if utils.match_response(http_res, "200", "application/json"):
return operations.PartitionResponse(
elements=utils.unmarshal_json(
http_res.text, Optional[List[Dict[str, Any]]]
),
status_code=http_res.status_code,
content_type=http_res.headers.get("Content-Type") or "",
raw_response=http_res,
)
if utils.match_response(http_res, "200", "text/csv"):
return operations.PartitionResponse(
csv_elements=http_res.text,
status_code=http_res.status_code,
content_type=http_res.headers.get("Content-Type") or "",
raw_response=http_res,
)
if utils.match_response(http_res, "422", "application/json"):
response_data = utils.unmarshal_json(
http_res.text, errors.HTTPValidationErrorData
)
raise errors.HTTPValidationError(data=response_data)
if utils.match_response(http_res, "4XX", "*"):
http_res_text = utils.stream_to_text(http_res)
raise errors.SDKError(
"API error occurred", http_res.status_code, http_res_text, http_res
)
if utils.match_response(http_res, "5XX", "application/json"):
response_data = utils.unmarshal_json(http_res.text, errors.ServerErrorData)
raise errors.ServerError(data=response_data)
content_type = http_res.headers.get("Content-Type")
http_res_text = utils.stream_to_text(http_res)
raise errors.SDKError(
f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
http_res.status_code,
http_res_text,
http_res,
)
async def partition_async(
self,
*,
request: Union[
operations.PartitionRequest, operations.PartitionRequestTypedDict
],
retries: OptionalNullable[utils.RetryConfig] = UNSET,
server_url: Optional[str] = None,
timeout_ms: Optional[int] = None,
accept_header_override: Optional[PartitionAcceptEnum] = None,
http_headers: Optional[Mapping[str, str]] = None,
) -> operations.PartitionResponse:
r"""Summary
Description
:param request: The request object to send.
:param retries: Override the default retry configuration for this method
:param server_url: Override the default server URL for this method
:param timeout_ms: Override the default request timeout configuration for this method in milliseconds
:param accept_header_override: Override the default accept header for this method
:param http_headers: Additional headers to set or replace on requests.
"""
base_url = clean_server_url(server_url) if server_url is not None else self.get_default_server_url()
url_variables = None
if timeout_ms is None:
timeout_ms = self.sdk_configuration.timeout_ms
if not isinstance(request, BaseModel):
request = utils.unmarshal(request, operations.PartitionRequest)
request = cast(operations.PartitionRequest, request)
req = self._build_request_async(
method="POST",
path="/general/v0/general",
base_url=base_url,
url_variables=url_variables,
request=request,
request_body_required=True,
request_has_path_params=False,
request_has_query_params=True,
user_agent_header="user-agent",
accept_header_value=accept_header_override.value
if accept_header_override is not None
else "application/json;q=1, text/csv;q=0",
http_headers=http_headers,
security=self.sdk_configuration.security,
get_serialized_body=lambda: utils.serialize_request_body(
request.partition_parameters,
False,
False,
"multipart",
shared.PartitionParameters,
),
timeout_ms=timeout_ms,
)
if retries == UNSET:
if self.sdk_configuration.retry_config is not UNSET:
retries = self.sdk_configuration.retry_config
else:
retries = utils.RetryConfig(
"backoff", utils.BackoffStrategy(3000, 720000, 1.88, 1800000), True
)
retry_config = None
if isinstance(retries, utils.RetryConfig):
retry_config = (retries, ["5xx"])
http_res = await self.do_request_async(
hook_ctx=HookContext(
base_url=base_url or "",
operation_id="partition",
oauth2_scopes=[],
security_source=self.sdk_configuration.security,
),
request=req,
error_status_codes=["422", "4XX", "5XX"],
retry_config=retry_config,
)
response_data: Any = None
if utils.match_response(http_res, "200", "application/json"):
return operations.PartitionResponse(
elements=utils.unmarshal_json(
http_res.text, Optional[List[Dict[str, Any]]]
),
status_code=http_res.status_code,
content_type=http_res.headers.get("Content-Type") or "",
raw_response=http_res,
)
if utils.match_response(http_res, "200", "text/csv"):
return operations.PartitionResponse(
csv_elements=http_res.text,
status_code=http_res.status_code,
content_type=http_res.headers.get("Content-Type") or "",
raw_response=http_res,
)
if utils.match_response(http_res, "422", "application/json"):
response_data = utils.unmarshal_json(
http_res.text, errors.HTTPValidationErrorData
)
raise errors.HTTPValidationError(data=response_data)
if utils.match_response(http_res, "4XX", "*"):
http_res_text = await utils.stream_to_text_async(http_res)
raise errors.SDKError(
"API error occurred", http_res.status_code, http_res_text, http_res
)
if utils.match_response(http_res, "5XX", "application/json"):
response_data = utils.unmarshal_json(http_res.text, errors.ServerErrorData)
raise errors.ServerError(data=response_data)
content_type = http_res.headers.get("Content-Type")
http_res_text = await utils.stream_to_text_async(http_res)
raise errors.SDKError(
f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
http_res.status_code,
http_res_text,
http_res,
)