crypticorn 2.17.0rc3__py3-none-any.whl → 2.17.0rc5__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- crypticorn/auth/client/api/admin_api.py +0 -2
- crypticorn/auth/client/api/auth_api.py +0 -4
- crypticorn/auth/client/api/service_api.py +0 -4
- crypticorn/auth/client/api/user_api.py +0 -4
- crypticorn/auth/client/api/wallet_api.py +0 -4
- crypticorn/auth/client/api_client.py +0 -5
- crypticorn/auth/client/models/add_wallet_request.py +1 -1
- crypticorn/auth/client/models/authorize_user_request.py +1 -1
- crypticorn/auth/client/models/create_api_key_request.py +1 -1
- crypticorn/auth/client/models/create_user_request.py +1 -1
- crypticorn/auth/client/models/get_api_keys200_response_inner.py +1 -1
- crypticorn/auth/client/models/list_wallets200_response_balances_inner_sale_round.py +1 -1
- crypticorn/auth/client/models/list_wallets200_response_balances_inner_wallet.py +1 -1
- crypticorn/auth/client/models/list_wallets200_response_balances_inner_wallet_vesting_wallets_inner.py +1 -1
- crypticorn/auth/client/models/list_wallets200_response_data_inner.py +1 -1
- crypticorn/auth/client/models/logout_default_response.py +1 -1
- crypticorn/auth/client/models/oauth_callback200_response_user.py +1 -1
- crypticorn/auth/client/models/refresh_token_info200_response_user_session.py +1 -1
- crypticorn/auth/client/models/rotate_tokens200_response.py +1 -1
- crypticorn/auth/client/models/token_info200_response.py +1 -1
- crypticorn/auth/client/models/update_user_request.py +1 -1
- crypticorn/auth/client/models/user_by_username200_response.py +1 -1
- crypticorn/auth/client/models/verify200_response.py +1 -1
- crypticorn/auth/client/models/verify_email200_response_auth.py +1 -1
- crypticorn/auth/client/models/verify_email200_response_auth_auth.py +1 -1
- crypticorn/auth/client/models/whoami200_response.py +1 -1
- crypticorn/cli/init.py +1 -1
- crypticorn/cli/templates/.env.docker.temp +3 -0
- crypticorn/cli/templates/.env.example.temp +4 -0
- crypticorn/client.py +0 -1
- crypticorn/common/auth.py +5 -16
- crypticorn/common/decorators.py +1 -2
- crypticorn/common/enums.py +0 -2
- crypticorn/common/metrics.py +1 -1
- crypticorn/common/middleware.py +0 -1
- crypticorn/common/pagination.py +135 -22
- crypticorn/common/utils.py +1 -2
- crypticorn/dex/__init__.py +6 -0
- crypticorn/dex/client/__init__.py +49 -0
- crypticorn/dex/client/api/__init__.py +6 -0
- crypticorn/dex/client/api/admin_api.py +3046 -0
- crypticorn/dex/client/api/signals_api.py +1821 -0
- crypticorn/dex/client/api/status_api.py +907 -0
- crypticorn/dex/client/api_client.py +753 -0
- crypticorn/dex/client/api_response.py +20 -0
- crypticorn/dex/client/configuration.py +620 -0
- crypticorn/dex/client/exceptions.py +220 -0
- crypticorn/dex/client/models/__init__.py +30 -0
- crypticorn/dex/client/models/api_error_identifier.py +121 -0
- crypticorn/dex/client/models/api_error_level.py +37 -0
- crypticorn/dex/client/models/api_error_type.py +37 -0
- crypticorn/dex/client/models/exception_detail.py +117 -0
- crypticorn/dex/client/models/log_level.py +38 -0
- crypticorn/dex/client/models/paginated_response_signal_with_token.py +134 -0
- crypticorn/dex/client/models/risk.py +86 -0
- crypticorn/dex/client/models/signal_overview_stats.py +156 -0
- crypticorn/dex/client/models/signal_volume.py +84 -0
- crypticorn/dex/client/models/signal_with_token.py +163 -0
- crypticorn/dex/client/models/token_data.py +127 -0
- crypticorn/dex/client/models/token_detail.py +116 -0
- crypticorn/dex/client/py.typed +0 -0
- crypticorn/dex/client/rest.py +217 -0
- crypticorn/dex/main.py +1 -0
- crypticorn/hive/client/api/admin_api.py +0 -3
- crypticorn/hive/client/api/data_api.py +0 -4
- crypticorn/hive/client/api/models_api.py +1 -4
- crypticorn/hive/client/api/status_api.py +0 -3
- crypticorn/hive/client/api_client.py +0 -5
- crypticorn/hive/client/models/coin_info.py +1 -1
- crypticorn/hive/client/models/exception_detail.py +1 -1
- crypticorn/hive/client/models/target_info.py +1 -1
- crypticorn/hive/utils.py +2 -2
- crypticorn/klines/client/api/admin_api.py +0 -3
- crypticorn/klines/client/api/change_in_timeframe_api.py +0 -4
- crypticorn/klines/client/api/funding_rates_api.py +0 -4
- crypticorn/klines/client/api/ohlcv_data_api.py +0 -4
- crypticorn/klines/client/api/status_api.py +0 -3
- crypticorn/klines/client/api/symbols_api.py +0 -4
- crypticorn/klines/client/api/udf_api.py +0 -2
- crypticorn/klines/client/api_client.py +0 -5
- crypticorn/klines/client/models/exception_detail.py +1 -1
- crypticorn/klines/client/models/ohlcv.py +1 -1
- crypticorn/klines/client/models/symbol_group.py +1 -1
- crypticorn/klines/client/models/udf_config.py +1 -1
- crypticorn/metrics/client/api/admin_api.py +0 -3
- crypticorn/metrics/client/api/exchanges_api.py +0 -4
- crypticorn/metrics/client/api/indicators_api.py +0 -4
- crypticorn/metrics/client/api/logs_api.py +0 -4
- crypticorn/metrics/client/api/marketcap_api.py +0 -4
- crypticorn/metrics/client/api/markets_api.py +0 -4
- crypticorn/metrics/client/api/quote_currencies_api.py +0 -4
- crypticorn/metrics/client/api/status_api.py +0 -3
- crypticorn/metrics/client/api/tokens_api.py +0 -2
- crypticorn/metrics/client/api_client.py +0 -5
- crypticorn/metrics/client/models/exception_detail.py +1 -1
- crypticorn/metrics/client/models/exchange_mapping.py +1 -1
- crypticorn/metrics/client/models/marketcap_ranking.py +1 -1
- crypticorn/metrics/client/models/marketcap_symbol_ranking.py +1 -1
- crypticorn/metrics/client/models/ohlcv.py +1 -1
- crypticorn/pay/client/api/admin_api.py +0 -3
- crypticorn/pay/client/api/now_payments_api.py +0 -4
- crypticorn/pay/client/api/payments_api.py +0 -4
- crypticorn/pay/client/api/products_api.py +0 -4
- crypticorn/pay/client/api/status_api.py +0 -3
- crypticorn/pay/client/api_client.py +0 -5
- crypticorn/pay/client/models/exception_detail.py +1 -1
- crypticorn/pay/client/models/now_create_invoice_req.py +1 -1
- crypticorn/pay/client/models/now_create_invoice_res.py +1 -1
- crypticorn/pay/client/models/product.py +1 -1
- crypticorn/pay/client/models/product_create.py +1 -1
- crypticorn/pay/client/models/product_update.py +1 -1
- crypticorn/trade/client/__init__.py +5 -0
- crypticorn/trade/client/api/admin_api.py +22 -23
- crypticorn/trade/client/api/bots_api.py +4712 -168
- crypticorn/trade/client/api/orders_api.py +220 -106
- crypticorn/trade/client/configuration.py +2 -2
- crypticorn/trade/client/models/__init__.py +5 -0
- crypticorn/trade/client/models/bot.py +7 -18
- crypticorn/trade/client/models/bot_create.py +17 -1
- crypticorn/trade/client/models/bot_update.py +17 -1
- crypticorn/trade/client/models/exchange_key_create.py +17 -1
- crypticorn/trade/client/models/exchange_key_update.py +17 -1
- crypticorn/trade/client/models/notification.py +17 -1
- crypticorn/trade/client/models/notification_create.py +17 -1
- crypticorn/trade/client/models/notification_update.py +17 -1
- crypticorn/trade/client/models/orders_count.py +88 -0
- crypticorn/trade/client/models/paginated_response_order.py +134 -0
- crypticorn/trade/client/models/pn_l.py +95 -0
- crypticorn/trade/client/models/strategy.py +17 -1
- crypticorn/trade/client/models/strategy_create.py +17 -1
- crypticorn/trade/client/models/strategy_update.py +17 -1
- {crypticorn-2.17.0rc3.dist-info → crypticorn-2.17.0rc5.dist-info}/METADATA +1 -1
- {crypticorn-2.17.0rc3.dist-info → crypticorn-2.17.0rc5.dist-info}/RECORD +137 -106
- {crypticorn-2.17.0rc3.dist-info → crypticorn-2.17.0rc5.dist-info}/WHEEL +0 -0
- {crypticorn-2.17.0rc3.dist-info → crypticorn-2.17.0rc5.dist-info}/entry_points.txt +0 -0
- {crypticorn-2.17.0rc3.dist-info → crypticorn-2.17.0rc5.dist-info}/licenses/LICENSE +0 -0
- {crypticorn-2.17.0rc3.dist-info → crypticorn-2.17.0rc5.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,753 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
"""
|
4
|
+
DEX AI API
|
5
|
+
|
6
|
+
API for DEX AI
|
7
|
+
|
8
|
+
The version of the OpenAPI document: 1.0.0
|
9
|
+
Generated by OpenAPI Generator (https://openapi-generator.tech)
|
10
|
+
|
11
|
+
Do not edit the class manually.
|
12
|
+
""" # noqa: E501
|
13
|
+
|
14
|
+
|
15
|
+
import datetime
|
16
|
+
from dateutil.parser import parse
|
17
|
+
from enum import Enum
|
18
|
+
import decimal
|
19
|
+
import json
|
20
|
+
import mimetypes
|
21
|
+
import os
|
22
|
+
import re
|
23
|
+
import tempfile
|
24
|
+
|
25
|
+
from urllib.parse import quote
|
26
|
+
from typing import Tuple, Optional, List, Dict, Union
|
27
|
+
from pydantic import SecretStr
|
28
|
+
|
29
|
+
from crypticorn.dex.client.configuration import Configuration
|
30
|
+
from crypticorn.dex.client.api_response import ApiResponse, T as ApiResponseT
|
31
|
+
import crypticorn.dex.client.models
|
32
|
+
from crypticorn.dex.client import rest
|
33
|
+
from crypticorn.dex.client.exceptions import (
|
34
|
+
ApiValueError,
|
35
|
+
ApiException,
|
36
|
+
)
|
37
|
+
|
38
|
+
RequestSerialized = Tuple[str, str, Dict[str, str], Optional[str], List[str]]
|
39
|
+
|
40
|
+
|
41
|
+
class ApiClient:
|
42
|
+
"""Generic API client for OpenAPI client library builds.
|
43
|
+
|
44
|
+
OpenAPI generic API client. This client handles the client-
|
45
|
+
server communication, and is invariant across implementations. Specifics of
|
46
|
+
the methods and models for each application are generated from the OpenAPI
|
47
|
+
templates.
|
48
|
+
|
49
|
+
:param configuration: .Configuration object for this client
|
50
|
+
:param header_name: a header to pass when making calls to the API.
|
51
|
+
:param header_value: a header value to pass when making calls to
|
52
|
+
the API.
|
53
|
+
:param cookie: a cookie to include in the header when making calls
|
54
|
+
to the API
|
55
|
+
"""
|
56
|
+
|
57
|
+
PRIMITIVE_TYPES = (float, bool, bytes, str, int)
|
58
|
+
NATIVE_TYPES_MAPPING = {
|
59
|
+
"int": int,
|
60
|
+
"long": int, # TODO remove as only py3 is supported?
|
61
|
+
"float": float,
|
62
|
+
"str": str,
|
63
|
+
"bool": bool,
|
64
|
+
"date": datetime.date,
|
65
|
+
"datetime": datetime.datetime,
|
66
|
+
"decimal": decimal.Decimal,
|
67
|
+
"object": object,
|
68
|
+
}
|
69
|
+
_pool = None
|
70
|
+
|
71
|
+
def __init__(
|
72
|
+
self, configuration=None, header_name=None, header_value=None, cookie=None
|
73
|
+
) -> None:
|
74
|
+
# use default configuration if none is provided
|
75
|
+
if configuration is None:
|
76
|
+
configuration = Configuration.get_default()
|
77
|
+
self.configuration = configuration
|
78
|
+
|
79
|
+
self.rest_client = rest.RESTClientObject(configuration)
|
80
|
+
self.default_headers = {}
|
81
|
+
if header_name is not None:
|
82
|
+
self.default_headers[header_name] = header_value
|
83
|
+
self.cookie = cookie
|
84
|
+
# Set default User-Agent.
|
85
|
+
self.user_agent = "OpenAPI-Generator/1.0.0/python"
|
86
|
+
self.client_side_validation = configuration.client_side_validation
|
87
|
+
|
88
|
+
async def __aenter__(self):
|
89
|
+
return self
|
90
|
+
|
91
|
+
async def __aexit__(self, exc_type, exc_value, traceback):
|
92
|
+
await self.close()
|
93
|
+
|
94
|
+
async def close(self):
|
95
|
+
await self.rest_client.close()
|
96
|
+
|
97
|
+
@property
|
98
|
+
def user_agent(self):
|
99
|
+
"""User agent for this API client"""
|
100
|
+
return self.default_headers["User-Agent"]
|
101
|
+
|
102
|
+
@user_agent.setter
|
103
|
+
def user_agent(self, value):
|
104
|
+
self.default_headers["User-Agent"] = value
|
105
|
+
|
106
|
+
def set_default_header(self, header_name, header_value):
|
107
|
+
self.default_headers[header_name] = header_value
|
108
|
+
|
109
|
+
_default = None
|
110
|
+
|
111
|
+
@classmethod
|
112
|
+
def get_default(cls):
|
113
|
+
"""Return new instance of ApiClient.
|
114
|
+
|
115
|
+
This method returns newly created, based on default constructor,
|
116
|
+
object of ApiClient class or returns a copy of default
|
117
|
+
ApiClient.
|
118
|
+
|
119
|
+
:return: The ApiClient object.
|
120
|
+
"""
|
121
|
+
if cls._default is None:
|
122
|
+
cls._default = ApiClient()
|
123
|
+
return cls._default
|
124
|
+
|
125
|
+
@classmethod
|
126
|
+
def set_default(cls, default):
|
127
|
+
"""Set default instance of ApiClient.
|
128
|
+
|
129
|
+
It stores default ApiClient.
|
130
|
+
|
131
|
+
:param default: object of ApiClient.
|
132
|
+
"""
|
133
|
+
cls._default = default
|
134
|
+
|
135
|
+
def param_serialize(
|
136
|
+
self,
|
137
|
+
method,
|
138
|
+
resource_path,
|
139
|
+
path_params=None,
|
140
|
+
query_params=None,
|
141
|
+
header_params=None,
|
142
|
+
body=None,
|
143
|
+
post_params=None,
|
144
|
+
files=None,
|
145
|
+
auth_settings=None,
|
146
|
+
collection_formats=None,
|
147
|
+
_host=None,
|
148
|
+
_request_auth=None,
|
149
|
+
) -> RequestSerialized:
|
150
|
+
"""Builds the HTTP request params needed by the request.
|
151
|
+
:param method: Method to call.
|
152
|
+
:param resource_path: Path to method endpoint.
|
153
|
+
:param path_params: Path parameters in the url.
|
154
|
+
:param query_params: Query parameters in the url.
|
155
|
+
:param header_params: Header parameters to be
|
156
|
+
placed in the request header.
|
157
|
+
:param body: Request body.
|
158
|
+
:param post_params dict: Request post form parameters,
|
159
|
+
for `application/x-www-form-urlencoded`, `multipart/form-data`.
|
160
|
+
:param auth_settings list: Auth Settings names for the request.
|
161
|
+
:param files dict: key -> filename, value -> filepath,
|
162
|
+
for `multipart/form-data`.
|
163
|
+
:param collection_formats: dict of collection formats for path, query,
|
164
|
+
header, and post parameters.
|
165
|
+
:param _request_auth: set to override the auth_settings for an a single
|
166
|
+
request; this effectively ignores the authentication
|
167
|
+
in the spec for a single request.
|
168
|
+
:return: tuple of form (path, http_method, query_params, header_params,
|
169
|
+
body, post_params, files)
|
170
|
+
"""
|
171
|
+
|
172
|
+
config = self.configuration
|
173
|
+
|
174
|
+
# header parameters
|
175
|
+
header_params = header_params or {}
|
176
|
+
header_params.update(self.default_headers)
|
177
|
+
if self.cookie:
|
178
|
+
header_params["Cookie"] = self.cookie
|
179
|
+
if header_params:
|
180
|
+
header_params = self.sanitize_for_serialization(header_params)
|
181
|
+
header_params = dict(
|
182
|
+
self.parameters_to_tuples(header_params, collection_formats)
|
183
|
+
)
|
184
|
+
|
185
|
+
# path parameters
|
186
|
+
if path_params:
|
187
|
+
path_params = self.sanitize_for_serialization(path_params)
|
188
|
+
path_params = self.parameters_to_tuples(path_params, collection_formats)
|
189
|
+
for k, v in path_params:
|
190
|
+
# specified safe chars, encode everything
|
191
|
+
resource_path = resource_path.replace(
|
192
|
+
"{%s}" % k, quote(str(v), safe=config.safe_chars_for_path_param)
|
193
|
+
)
|
194
|
+
|
195
|
+
# post parameters
|
196
|
+
if post_params or files:
|
197
|
+
post_params = post_params if post_params else []
|
198
|
+
post_params = self.sanitize_for_serialization(post_params)
|
199
|
+
post_params = self.parameters_to_tuples(post_params, collection_formats)
|
200
|
+
if files:
|
201
|
+
post_params.extend(self.files_parameters(files))
|
202
|
+
|
203
|
+
# auth setting
|
204
|
+
self.update_params_for_auth(
|
205
|
+
header_params,
|
206
|
+
query_params,
|
207
|
+
auth_settings,
|
208
|
+
resource_path,
|
209
|
+
method,
|
210
|
+
body,
|
211
|
+
request_auth=_request_auth,
|
212
|
+
)
|
213
|
+
|
214
|
+
# body
|
215
|
+
if body:
|
216
|
+
body = self.sanitize_for_serialization(body)
|
217
|
+
|
218
|
+
# request url
|
219
|
+
if _host is None or self.configuration.ignore_operation_servers:
|
220
|
+
url = self.configuration.host + resource_path
|
221
|
+
else:
|
222
|
+
# use server/host defined in path or operation instead
|
223
|
+
url = _host + resource_path
|
224
|
+
|
225
|
+
# query parameters
|
226
|
+
if query_params:
|
227
|
+
query_params = self.sanitize_for_serialization(query_params)
|
228
|
+
url_query = self.parameters_to_url_query(query_params, collection_formats)
|
229
|
+
url += "?" + url_query
|
230
|
+
|
231
|
+
return method, url, header_params, body, post_params
|
232
|
+
|
233
|
+
async def call_api(
|
234
|
+
self,
|
235
|
+
method,
|
236
|
+
url,
|
237
|
+
header_params=None,
|
238
|
+
body=None,
|
239
|
+
post_params=None,
|
240
|
+
_request_timeout=None,
|
241
|
+
) -> rest.RESTResponse:
|
242
|
+
"""Makes the HTTP request (synchronous)
|
243
|
+
:param method: Method to call.
|
244
|
+
:param url: Path to method endpoint.
|
245
|
+
:param header_params: Header parameters to be
|
246
|
+
placed in the request header.
|
247
|
+
:param body: Request body.
|
248
|
+
:param post_params dict: Request post form parameters,
|
249
|
+
for `application/x-www-form-urlencoded`, `multipart/form-data`.
|
250
|
+
:param _request_timeout: timeout setting for this request.
|
251
|
+
:return: RESTResponse
|
252
|
+
"""
|
253
|
+
|
254
|
+
try:
|
255
|
+
# perform request and return response
|
256
|
+
response_data = await self.rest_client.request(
|
257
|
+
method,
|
258
|
+
url,
|
259
|
+
headers=header_params,
|
260
|
+
body=body,
|
261
|
+
post_params=post_params,
|
262
|
+
_request_timeout=_request_timeout,
|
263
|
+
)
|
264
|
+
|
265
|
+
except ApiException as e:
|
266
|
+
raise e
|
267
|
+
|
268
|
+
return response_data
|
269
|
+
|
270
|
+
def response_deserialize(
|
271
|
+
self,
|
272
|
+
response_data: rest.RESTResponse,
|
273
|
+
response_types_map: Optional[Dict[str, ApiResponseT]] = None,
|
274
|
+
) -> ApiResponse[ApiResponseT]:
|
275
|
+
"""Deserializes response into an object.
|
276
|
+
:param response_data: RESTResponse object to be deserialized.
|
277
|
+
:param response_types_map: dict of response types.
|
278
|
+
:return: ApiResponse
|
279
|
+
"""
|
280
|
+
|
281
|
+
msg = "RESTResponse.read() must be called before passing it to response_deserialize()"
|
282
|
+
assert response_data.data is not None, msg
|
283
|
+
|
284
|
+
response_type = response_types_map.get(str(response_data.status), None)
|
285
|
+
if (
|
286
|
+
not response_type
|
287
|
+
and isinstance(response_data.status, int)
|
288
|
+
and 100 <= response_data.status <= 599
|
289
|
+
):
|
290
|
+
# if not found, look for '1XX', '2XX', etc.
|
291
|
+
response_type = response_types_map.get(
|
292
|
+
str(response_data.status)[0] + "XX", None
|
293
|
+
)
|
294
|
+
|
295
|
+
# deserialize response data
|
296
|
+
response_text = None
|
297
|
+
return_data = None
|
298
|
+
try:
|
299
|
+
if response_type == "bytearray":
|
300
|
+
return_data = response_data.data
|
301
|
+
elif response_type == "file":
|
302
|
+
return_data = self.__deserialize_file(response_data)
|
303
|
+
elif response_type is not None:
|
304
|
+
match = None
|
305
|
+
content_type = response_data.getheader("content-type")
|
306
|
+
if content_type is not None:
|
307
|
+
match = re.search(r"charset=([a-zA-Z\-\d]+)[\s;]?", content_type)
|
308
|
+
encoding = match.group(1) if match else "utf-8"
|
309
|
+
response_text = response_data.data.decode(encoding)
|
310
|
+
return_data = self.deserialize(
|
311
|
+
response_text, response_type, content_type
|
312
|
+
)
|
313
|
+
finally:
|
314
|
+
if not 200 <= response_data.status <= 299:
|
315
|
+
raise ApiException.from_response(
|
316
|
+
http_resp=response_data,
|
317
|
+
body=response_text,
|
318
|
+
data=return_data,
|
319
|
+
)
|
320
|
+
|
321
|
+
return ApiResponse(
|
322
|
+
status_code=response_data.status,
|
323
|
+
data=return_data,
|
324
|
+
headers=response_data.getheaders(),
|
325
|
+
raw_data=response_data.data,
|
326
|
+
)
|
327
|
+
|
328
|
+
def sanitize_for_serialization(self, obj):
|
329
|
+
"""Builds a JSON POST object.
|
330
|
+
|
331
|
+
If obj is None, return None.
|
332
|
+
If obj is SecretStr, return obj.get_secret_value()
|
333
|
+
If obj is str, int, long, float, bool, return directly.
|
334
|
+
If obj is datetime.datetime, datetime.date
|
335
|
+
convert to string in iso8601 format.
|
336
|
+
If obj is decimal.Decimal return string representation.
|
337
|
+
If obj is list, sanitize each element in the list.
|
338
|
+
If obj is dict, return the dict.
|
339
|
+
If obj is OpenAPI model, return the properties dict.
|
340
|
+
|
341
|
+
:param obj: The data to serialize.
|
342
|
+
:return: The serialized form of data.
|
343
|
+
"""
|
344
|
+
if obj is None:
|
345
|
+
return None
|
346
|
+
elif isinstance(obj, Enum):
|
347
|
+
return obj.value
|
348
|
+
elif isinstance(obj, SecretStr):
|
349
|
+
return obj.get_secret_value()
|
350
|
+
elif isinstance(obj, self.PRIMITIVE_TYPES):
|
351
|
+
return obj
|
352
|
+
elif isinstance(obj, list):
|
353
|
+
return [self.sanitize_for_serialization(sub_obj) for sub_obj in obj]
|
354
|
+
elif isinstance(obj, tuple):
|
355
|
+
return tuple(self.sanitize_for_serialization(sub_obj) for sub_obj in obj)
|
356
|
+
elif isinstance(obj, (datetime.datetime, datetime.date)):
|
357
|
+
return obj.isoformat()
|
358
|
+
elif isinstance(obj, decimal.Decimal):
|
359
|
+
return str(obj)
|
360
|
+
|
361
|
+
elif isinstance(obj, dict):
|
362
|
+
obj_dict = obj
|
363
|
+
else:
|
364
|
+
# Convert model obj to dict except
|
365
|
+
# attributes `openapi_types`, `attribute_map`
|
366
|
+
# and attributes which value is not None.
|
367
|
+
# Convert attribute name to json key in
|
368
|
+
# model definition for request.
|
369
|
+
if hasattr(obj, "to_dict") and callable(getattr(obj, "to_dict")):
|
370
|
+
obj_dict = obj.to_dict()
|
371
|
+
else:
|
372
|
+
obj_dict = obj.__dict__
|
373
|
+
|
374
|
+
return {
|
375
|
+
key: self.sanitize_for_serialization(val) for key, val in obj_dict.items()
|
376
|
+
}
|
377
|
+
|
378
|
+
def deserialize(
|
379
|
+
self, response_text: str, response_type: str, content_type: Optional[str]
|
380
|
+
):
|
381
|
+
"""Deserializes response into an object.
|
382
|
+
|
383
|
+
:param response: RESTResponse object to be deserialized.
|
384
|
+
:param response_type: class literal for
|
385
|
+
deserialized object, or string of class name.
|
386
|
+
:param content_type: content type of response.
|
387
|
+
|
388
|
+
:return: deserialized object.
|
389
|
+
"""
|
390
|
+
|
391
|
+
# fetch data from response object
|
392
|
+
if content_type is None:
|
393
|
+
try:
|
394
|
+
data = json.loads(response_text)
|
395
|
+
except ValueError:
|
396
|
+
data = response_text
|
397
|
+
elif re.match(
|
398
|
+
r"^application/(json|[\w!#$&.+-^_]+\+json)\s*(;|$)",
|
399
|
+
content_type,
|
400
|
+
re.IGNORECASE,
|
401
|
+
):
|
402
|
+
if response_text == "":
|
403
|
+
data = ""
|
404
|
+
else:
|
405
|
+
data = json.loads(response_text)
|
406
|
+
elif re.match(r"^text\/[a-z.+-]+\s*(;|$)", content_type, re.IGNORECASE):
|
407
|
+
data = response_text
|
408
|
+
else:
|
409
|
+
raise ApiException(
|
410
|
+
status=0, reason="Unsupported content type: {0}".format(content_type)
|
411
|
+
)
|
412
|
+
|
413
|
+
return self.__deserialize(data, response_type)
|
414
|
+
|
415
|
+
def __deserialize(self, data, klass):
|
416
|
+
"""Deserializes dict, list, str into an object.
|
417
|
+
|
418
|
+
:param data: dict, list or str.
|
419
|
+
:param klass: class literal, or string of class name.
|
420
|
+
|
421
|
+
:return: object.
|
422
|
+
"""
|
423
|
+
if data is None:
|
424
|
+
return None
|
425
|
+
|
426
|
+
if isinstance(klass, str):
|
427
|
+
if klass.startswith("List["):
|
428
|
+
m = re.match(r"List\[(.*)]", klass)
|
429
|
+
assert m is not None, "Malformed List type definition"
|
430
|
+
sub_kls = m.group(1)
|
431
|
+
return [self.__deserialize(sub_data, sub_kls) for sub_data in data]
|
432
|
+
|
433
|
+
if klass.startswith("Dict["):
|
434
|
+
m = re.match(r"Dict\[([^,]*), (.*)]", klass)
|
435
|
+
assert m is not None, "Malformed Dict type definition"
|
436
|
+
sub_kls = m.group(2)
|
437
|
+
return {k: self.__deserialize(v, sub_kls) for k, v in data.items()}
|
438
|
+
|
439
|
+
# convert str to class
|
440
|
+
if klass in self.NATIVE_TYPES_MAPPING:
|
441
|
+
klass = self.NATIVE_TYPES_MAPPING[klass]
|
442
|
+
else:
|
443
|
+
klass = getattr(crypticorn.dex.client.models, klass)
|
444
|
+
|
445
|
+
if klass in self.PRIMITIVE_TYPES:
|
446
|
+
return self.__deserialize_primitive(data, klass)
|
447
|
+
elif klass == object:
|
448
|
+
return self.__deserialize_object(data)
|
449
|
+
elif klass == datetime.date:
|
450
|
+
return self.__deserialize_date(data)
|
451
|
+
elif klass == datetime.datetime:
|
452
|
+
return self.__deserialize_datetime(data)
|
453
|
+
elif klass == decimal.Decimal:
|
454
|
+
return decimal.Decimal(data)
|
455
|
+
elif issubclass(klass, Enum):
|
456
|
+
return self.__deserialize_enum(data, klass)
|
457
|
+
else:
|
458
|
+
return self.__deserialize_model(data, klass)
|
459
|
+
|
460
|
+
def parameters_to_tuples(self, params, collection_formats):
|
461
|
+
"""Get parameters as list of tuples, formatting collections.
|
462
|
+
|
463
|
+
:param params: Parameters as dict or list of two-tuples
|
464
|
+
:param dict collection_formats: Parameter collection formats
|
465
|
+
:return: Parameters as list of tuples, collections formatted
|
466
|
+
"""
|
467
|
+
new_params: List[Tuple[str, str]] = []
|
468
|
+
if collection_formats is None:
|
469
|
+
collection_formats = {}
|
470
|
+
for k, v in params.items() if isinstance(params, dict) else params:
|
471
|
+
if k in collection_formats:
|
472
|
+
collection_format = collection_formats[k]
|
473
|
+
if collection_format == "multi":
|
474
|
+
new_params.extend((k, value) for value in v)
|
475
|
+
else:
|
476
|
+
if collection_format == "ssv":
|
477
|
+
delimiter = " "
|
478
|
+
elif collection_format == "tsv":
|
479
|
+
delimiter = "\t"
|
480
|
+
elif collection_format == "pipes":
|
481
|
+
delimiter = "|"
|
482
|
+
else: # csv is the default
|
483
|
+
delimiter = ","
|
484
|
+
new_params.append((k, delimiter.join(str(value) for value in v)))
|
485
|
+
else:
|
486
|
+
new_params.append((k, v))
|
487
|
+
return new_params
|
488
|
+
|
489
|
+
def parameters_to_url_query(self, params, collection_formats):
|
490
|
+
"""Get parameters as list of tuples, formatting collections.
|
491
|
+
|
492
|
+
:param params: Parameters as dict or list of two-tuples
|
493
|
+
:param dict collection_formats: Parameter collection formats
|
494
|
+
:return: URL query string (e.g. a=Hello%20World&b=123)
|
495
|
+
"""
|
496
|
+
new_params: List[Tuple[str, str]] = []
|
497
|
+
if collection_formats is None:
|
498
|
+
collection_formats = {}
|
499
|
+
for k, v in params.items() if isinstance(params, dict) else params:
|
500
|
+
if isinstance(v, bool):
|
501
|
+
v = str(v).lower()
|
502
|
+
if isinstance(v, (int, float)):
|
503
|
+
v = str(v)
|
504
|
+
if isinstance(v, dict):
|
505
|
+
v = json.dumps(v)
|
506
|
+
|
507
|
+
if k in collection_formats:
|
508
|
+
collection_format = collection_formats[k]
|
509
|
+
if collection_format == "multi":
|
510
|
+
new_params.extend((k, quote(str(value))) for value in v)
|
511
|
+
else:
|
512
|
+
if collection_format == "ssv":
|
513
|
+
delimiter = " "
|
514
|
+
elif collection_format == "tsv":
|
515
|
+
delimiter = "\t"
|
516
|
+
elif collection_format == "pipes":
|
517
|
+
delimiter = "|"
|
518
|
+
else: # csv is the default
|
519
|
+
delimiter = ","
|
520
|
+
new_params.append(
|
521
|
+
(k, delimiter.join(quote(str(value)) for value in v))
|
522
|
+
)
|
523
|
+
else:
|
524
|
+
new_params.append((k, quote(str(v))))
|
525
|
+
|
526
|
+
return "&".join(["=".join(map(str, item)) for item in new_params])
|
527
|
+
|
528
|
+
def files_parameters(
|
529
|
+
self,
|
530
|
+
files: Dict[str, Union[str, bytes, List[str], List[bytes], Tuple[str, bytes]]],
|
531
|
+
):
|
532
|
+
"""Builds form parameters.
|
533
|
+
|
534
|
+
:param files: File parameters.
|
535
|
+
:return: Form parameters with files.
|
536
|
+
"""
|
537
|
+
params = []
|
538
|
+
for k, v in files.items():
|
539
|
+
if isinstance(v, str):
|
540
|
+
with open(v, "rb") as f:
|
541
|
+
filename = os.path.basename(f.name)
|
542
|
+
filedata = f.read()
|
543
|
+
elif isinstance(v, bytes):
|
544
|
+
filename = k
|
545
|
+
filedata = v
|
546
|
+
elif isinstance(v, tuple):
|
547
|
+
filename, filedata = v
|
548
|
+
elif isinstance(v, list):
|
549
|
+
for file_param in v:
|
550
|
+
params.extend(self.files_parameters({k: file_param}))
|
551
|
+
continue
|
552
|
+
else:
|
553
|
+
raise ValueError("Unsupported file value")
|
554
|
+
mimetype = mimetypes.guess_type(filename)[0] or "application/octet-stream"
|
555
|
+
params.append(tuple([k, tuple([filename, filedata, mimetype])]))
|
556
|
+
return params
|
557
|
+
|
558
|
+
def select_header_accept(self, accepts: List[str]) -> Optional[str]:
|
559
|
+
"""Returns `Accept` based on an array of accepts provided.
|
560
|
+
|
561
|
+
:param accepts: List of headers.
|
562
|
+
:return: Accept (e.g. application/json).
|
563
|
+
"""
|
564
|
+
if not accepts:
|
565
|
+
return None
|
566
|
+
|
567
|
+
for accept in accepts:
|
568
|
+
if re.search("json", accept, re.IGNORECASE):
|
569
|
+
return accept
|
570
|
+
|
571
|
+
return accepts[0]
|
572
|
+
|
573
|
+
def select_header_content_type(self, content_types):
|
574
|
+
"""Returns `Content-Type` based on an array of content_types provided.
|
575
|
+
|
576
|
+
:param content_types: List of content-types.
|
577
|
+
:return: Content-Type (e.g. application/json).
|
578
|
+
"""
|
579
|
+
if not content_types:
|
580
|
+
return None
|
581
|
+
|
582
|
+
for content_type in content_types:
|
583
|
+
if re.search("json", content_type, re.IGNORECASE):
|
584
|
+
return content_type
|
585
|
+
|
586
|
+
return content_types[0]
|
587
|
+
|
588
|
+
def update_params_for_auth(
|
589
|
+
self,
|
590
|
+
headers,
|
591
|
+
queries,
|
592
|
+
auth_settings,
|
593
|
+
resource_path,
|
594
|
+
method,
|
595
|
+
body,
|
596
|
+
request_auth=None,
|
597
|
+
) -> None:
|
598
|
+
"""Updates header and query params based on authentication setting.
|
599
|
+
|
600
|
+
:param headers: Header parameters dict to be updated.
|
601
|
+
:param queries: Query parameters tuple list to be updated.
|
602
|
+
:param auth_settings: Authentication setting identifiers list.
|
603
|
+
:resource_path: A string representation of the HTTP request resource path.
|
604
|
+
:method: A string representation of the HTTP request method.
|
605
|
+
:body: A object representing the body of the HTTP request.
|
606
|
+
The object type is the return value of sanitize_for_serialization().
|
607
|
+
:param request_auth: if set, the provided settings will
|
608
|
+
override the token in the configuration.
|
609
|
+
"""
|
610
|
+
if not auth_settings:
|
611
|
+
return
|
612
|
+
|
613
|
+
if request_auth:
|
614
|
+
self._apply_auth_params(
|
615
|
+
headers, queries, resource_path, method, body, request_auth
|
616
|
+
)
|
617
|
+
else:
|
618
|
+
for auth in auth_settings:
|
619
|
+
auth_setting = self.configuration.auth_settings().get(auth)
|
620
|
+
if auth_setting:
|
621
|
+
self._apply_auth_params(
|
622
|
+
headers, queries, resource_path, method, body, auth_setting
|
623
|
+
)
|
624
|
+
|
625
|
+
def _apply_auth_params(
|
626
|
+
self, headers, queries, resource_path, method, body, auth_setting
|
627
|
+
) -> None:
|
628
|
+
"""Updates the request parameters based on a single auth_setting
|
629
|
+
|
630
|
+
:param headers: Header parameters dict to be updated.
|
631
|
+
:param queries: Query parameters tuple list to be updated.
|
632
|
+
:resource_path: A string representation of the HTTP request resource path.
|
633
|
+
:method: A string representation of the HTTP request method.
|
634
|
+
:body: A object representing the body of the HTTP request.
|
635
|
+
The object type is the return value of sanitize_for_serialization().
|
636
|
+
:param auth_setting: auth settings for the endpoint
|
637
|
+
"""
|
638
|
+
if auth_setting["in"] == "cookie":
|
639
|
+
headers["Cookie"] = auth_setting["value"]
|
640
|
+
elif auth_setting["in"] == "header":
|
641
|
+
if auth_setting["type"] != "http-signature":
|
642
|
+
headers[auth_setting["key"]] = auth_setting["value"]
|
643
|
+
elif auth_setting["in"] == "query":
|
644
|
+
queries.append((auth_setting["key"], auth_setting["value"]))
|
645
|
+
else:
|
646
|
+
raise ApiValueError("Authentication token must be in `query` or `header`")
|
647
|
+
|
648
|
+
def __deserialize_file(self, response):
|
649
|
+
"""Deserializes body to file
|
650
|
+
|
651
|
+
Saves response body into a file in a temporary folder,
|
652
|
+
using the filename from the `Content-Disposition` header if provided.
|
653
|
+
|
654
|
+
handle file downloading
|
655
|
+
save response body into a tmp file and return the instance
|
656
|
+
|
657
|
+
:param response: RESTResponse.
|
658
|
+
:return: file path.
|
659
|
+
"""
|
660
|
+
fd, path = tempfile.mkstemp(dir=self.configuration.temp_folder_path)
|
661
|
+
os.close(fd)
|
662
|
+
os.remove(path)
|
663
|
+
|
664
|
+
content_disposition = response.getheader("Content-Disposition")
|
665
|
+
if content_disposition:
|
666
|
+
m = re.search(r'filename=[\'"]?([^\'"\s]+)[\'"]?', content_disposition)
|
667
|
+
assert m is not None, "Unexpected 'content-disposition' header value"
|
668
|
+
filename = m.group(1)
|
669
|
+
path = os.path.join(os.path.dirname(path), filename)
|
670
|
+
|
671
|
+
with open(path, "wb") as f:
|
672
|
+
f.write(response.data)
|
673
|
+
|
674
|
+
return path
|
675
|
+
|
676
|
+
def __deserialize_primitive(self, data, klass):
|
677
|
+
"""Deserializes string to primitive type.
|
678
|
+
|
679
|
+
:param data: str.
|
680
|
+
:param klass: class literal.
|
681
|
+
|
682
|
+
:return: int, long, float, str, bool.
|
683
|
+
"""
|
684
|
+
try:
|
685
|
+
return klass(data)
|
686
|
+
except UnicodeEncodeError:
|
687
|
+
return str(data)
|
688
|
+
except TypeError:
|
689
|
+
return data
|
690
|
+
|
691
|
+
def __deserialize_object(self, value):
|
692
|
+
"""Return an original value.
|
693
|
+
|
694
|
+
:return: object.
|
695
|
+
"""
|
696
|
+
return value
|
697
|
+
|
698
|
+
def __deserialize_date(self, string):
|
699
|
+
"""Deserializes string to date.
|
700
|
+
|
701
|
+
:param string: str.
|
702
|
+
:return: date.
|
703
|
+
"""
|
704
|
+
try:
|
705
|
+
return parse(string).date()
|
706
|
+
except ImportError:
|
707
|
+
return string
|
708
|
+
except ValueError:
|
709
|
+
raise rest.ApiException(
|
710
|
+
status=0, reason="Failed to parse `{0}` as date object".format(string)
|
711
|
+
)
|
712
|
+
|
713
|
+
def __deserialize_datetime(self, string):
|
714
|
+
"""Deserializes string to datetime.
|
715
|
+
|
716
|
+
The string should be in iso8601 datetime format.
|
717
|
+
|
718
|
+
:param string: str.
|
719
|
+
:return: datetime.
|
720
|
+
"""
|
721
|
+
try:
|
722
|
+
return parse(string)
|
723
|
+
except ImportError:
|
724
|
+
return string
|
725
|
+
except ValueError:
|
726
|
+
raise rest.ApiException(
|
727
|
+
status=0,
|
728
|
+
reason=("Failed to parse `{0}` as datetime object".format(string)),
|
729
|
+
)
|
730
|
+
|
731
|
+
def __deserialize_enum(self, data, klass):
|
732
|
+
"""Deserializes primitive type to enum.
|
733
|
+
|
734
|
+
:param data: primitive type.
|
735
|
+
:param klass: class literal.
|
736
|
+
:return: enum value.
|
737
|
+
"""
|
738
|
+
try:
|
739
|
+
return klass(data)
|
740
|
+
except ValueError:
|
741
|
+
raise rest.ApiException(
|
742
|
+
status=0, reason=("Failed to parse `{0}` as `{1}`".format(data, klass))
|
743
|
+
)
|
744
|
+
|
745
|
+
def __deserialize_model(self, data, klass):
|
746
|
+
"""Deserializes list or dict to model.
|
747
|
+
|
748
|
+
:param data: dict, list.
|
749
|
+
:param klass: class literal.
|
750
|
+
:return: model object.
|
751
|
+
"""
|
752
|
+
|
753
|
+
return klass.from_dict(data)
|