qi-compute-api-client 0.7.0__py3-none-any.whl → 0.17.0__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.

Potentially problematic release.


This version of qi-compute-api-client might be problematic. Click here for more details.

Files changed (165) hide show
  1. compute_api_client/__init__.py +22 -19
  2. compute_api_client/api/__init__.py +5 -6
  3. compute_api_client/api/algorithms_api.py +1333 -553
  4. compute_api_client/api/backend_api.py +1501 -0
  5. compute_api_client/api/backend_types_api.py +684 -0
  6. compute_api_client/api/batch_jobs_api.py +1937 -0
  7. compute_api_client/api/commits_api.py +1068 -435
  8. compute_api_client/api/files_api.py +1075 -435
  9. compute_api_client/api/final_results_api.py +736 -338
  10. compute_api_client/api/jobs_api.py +1653 -0
  11. compute_api_client/api/languages_api.py +556 -217
  12. compute_api_client/api/members_api.py +1057 -435
  13. compute_api_client/api/metadata_api.py +736 -337
  14. compute_api_client/api/permissions_api.py +1055 -421
  15. compute_api_client/api/projects_api.py +1604 -676
  16. compute_api_client/api/reservations_api.py +1124 -427
  17. compute_api_client/api/results_api.py +738 -337
  18. compute_api_client/api/teams_api.py +567 -220
  19. compute_api_client/api/transactions_api.py +679 -218
  20. compute_api_client/api/users_api.py +1090 -435
  21. compute_api_client/api_client.py +346 -304
  22. compute_api_client/api_response.py +21 -0
  23. compute_api_client/configuration.py +54 -67
  24. compute_api_client/docs/Algorithm.md +20 -3
  25. compute_api_client/docs/AlgorithmIn.md +20 -3
  26. compute_api_client/docs/AlgorithmType.md +0 -1
  27. compute_api_client/docs/AlgorithmsApi.md +78 -77
  28. compute_api_client/docs/Backend.md +33 -0
  29. compute_api_client/docs/BackendApi.md +419 -0
  30. compute_api_client/docs/BackendPatch.md +29 -0
  31. compute_api_client/docs/{RunStatus.md → BackendStatus.md} +1 -2
  32. compute_api_client/docs/BackendType.md +36 -0
  33. compute_api_client/docs/{RuntimeTypesApi.md → BackendTypesApi.md} +58 -31
  34. compute_api_client/docs/BackendWithAuthentication.md +34 -0
  35. compute_api_client/docs/BatchJob.md +38 -0
  36. compute_api_client/docs/BatchJobIn.md +29 -0
  37. compute_api_client/docs/{RuntimeStatus.md → BatchJobStatus.md} +1 -2
  38. compute_api_client/docs/{BatchRunsApi.md → BatchJobsApi.md} +170 -147
  39. compute_api_client/docs/Commit.md +18 -1
  40. compute_api_client/docs/CommitIn.md +17 -0
  41. compute_api_client/docs/CommitsApi.md +62 -71
  42. compute_api_client/docs/CompileStage.md +0 -1
  43. compute_api_client/docs/Domain.md +0 -1
  44. compute_api_client/docs/File.md +21 -4
  45. compute_api_client/docs/FileIn.md +21 -4
  46. compute_api_client/docs/FilesApi.md +65 -71
  47. compute_api_client/docs/FinalResult.md +20 -3
  48. compute_api_client/docs/FinalResultIn.md +19 -2
  49. compute_api_client/docs/FinalResultsApi.md +44 -71
  50. compute_api_client/docs/HTTPNotFoundError.md +17 -0
  51. compute_api_client/docs/HTTPValidationError.md +18 -1
  52. compute_api_client/docs/Job.md +36 -0
  53. compute_api_client/docs/JobIn.md +31 -0
  54. compute_api_client/docs/JobPatch.md +28 -0
  55. compute_api_client/docs/{BatchRunStatus.md → JobStatus.md} +1 -2
  56. compute_api_client/docs/{RunsApi.md → JobsApi.md} +137 -122
  57. compute_api_client/docs/Language.md +17 -0
  58. compute_api_client/docs/LanguagesApi.md +30 -12
  59. compute_api_client/docs/LocationInner.md +17 -0
  60. compute_api_client/docs/Member.md +19 -2
  61. compute_api_client/docs/MemberIn.md +19 -2
  62. compute_api_client/docs/MembersApi.md +59 -24
  63. compute_api_client/docs/Metadata.md +20 -3
  64. compute_api_client/docs/MetadataApi.md +49 -33
  65. compute_api_client/docs/MetadataIn.md +19 -2
  66. compute_api_client/docs/Permission.md +17 -0
  67. compute_api_client/docs/PermissionGroup.md +17 -0
  68. compute_api_client/docs/PermissionsApi.md +68 -28
  69. compute_api_client/docs/Project.md +20 -3
  70. compute_api_client/docs/ProjectIn.md +18 -1
  71. compute_api_client/docs/ProjectPatch.md +19 -2
  72. compute_api_client/docs/ProjectsApi.md +84 -36
  73. compute_api_client/docs/Reservation.md +21 -4
  74. compute_api_client/docs/ReservationIn.md +19 -2
  75. compute_api_client/docs/ReservationsApi.md +66 -24
  76. compute_api_client/docs/Result.md +23 -6
  77. compute_api_client/docs/ResultIn.md +19 -2
  78. compute_api_client/docs/ResultsApi.md +42 -26
  79. compute_api_client/docs/Role.md +0 -1
  80. compute_api_client/docs/ShareType.md +0 -1
  81. compute_api_client/docs/Team.md +18 -1
  82. compute_api_client/docs/TeamsApi.md +37 -14
  83. compute_api_client/docs/Transaction.md +21 -4
  84. compute_api_client/docs/TransactionsApi.md +50 -14
  85. compute_api_client/docs/User.md +21 -4
  86. compute_api_client/docs/UserIn.md +17 -0
  87. compute_api_client/docs/UsersApi.md +62 -24
  88. compute_api_client/docs/ValidationError.md +18 -1
  89. compute_api_client/exceptions.py +19 -16
  90. compute_api_client/models/__init__.py +16 -14
  91. compute_api_client/models/algorithm.py +78 -237
  92. compute_api_client/models/algorithm_in.py +76 -204
  93. compute_api_client/models/algorithm_type.py +21 -87
  94. compute_api_client/models/backend.py +100 -0
  95. compute_api_client/models/backend_patch.py +90 -0
  96. compute_api_client/models/backend_status.py +47 -0
  97. compute_api_client/models/backend_type.py +105 -0
  98. compute_api_client/models/backend_with_authentication.py +102 -0
  99. compute_api_client/models/batch_job.py +129 -0
  100. compute_api_client/models/batch_job_in.py +89 -0
  101. compute_api_client/models/batch_job_status.py +48 -0
  102. compute_api_client/models/commit.py +72 -230
  103. compute_api_client/models/commit_in.py +67 -169
  104. compute_api_client/models/compile_stage.py +23 -89
  105. compute_api_client/models/domain.py +22 -88
  106. compute_api_client/models/file.py +74 -288
  107. compute_api_client/models/file_in.py +72 -254
  108. compute_api_client/models/final_result.py +68 -198
  109. compute_api_client/models/final_result_in.py +63 -137
  110. compute_api_client/models/http_not_found_error.py +60 -105
  111. compute_api_client/models/http_validation_error.py +69 -105
  112. compute_api_client/models/job.py +120 -0
  113. compute_api_client/models/job_in.py +99 -0
  114. compute_api_client/models/job_patch.py +88 -0
  115. compute_api_client/models/job_status.py +48 -0
  116. compute_api_client/models/language.py +67 -172
  117. compute_api_client/models/location_inner.py +125 -84
  118. compute_api_client/models/member.py +70 -236
  119. compute_api_client/models/member_in.py +68 -203
  120. compute_api_client/models/metadata.py +68 -198
  121. compute_api_client/models/metadata_in.py +68 -137
  122. compute_api_client/models/permission.py +67 -172
  123. compute_api_client/models/permission_group.py +65 -142
  124. compute_api_client/models/project.py +74 -256
  125. compute_api_client/models/project_in.py +69 -195
  126. compute_api_client/models/project_patch.py +89 -192
  127. compute_api_client/models/reservation.py +79 -290
  128. compute_api_client/models/reservation_in.py +68 -200
  129. compute_api_client/models/result.py +101 -359
  130. compute_api_client/models/result_in.py +95 -291
  131. compute_api_client/models/role.py +21 -87
  132. compute_api_client/models/share_type.py +22 -88
  133. compute_api_client/models/team.py +69 -198
  134. compute_api_client/models/transaction.py +93 -299
  135. compute_api_client/models/user.py +75 -276
  136. compute_api_client/models/user_in.py +73 -243
  137. compute_api_client/models/validation_error.py +73 -160
  138. compute_api_client/rest.py +55 -114
  139. {qi_compute_api_client-0.7.0.dist-info → qi_compute_api_client-0.17.0.dist-info}/METADATA +47 -40
  140. qi_compute_api_client-0.17.0.dist-info/RECORD +142 -0
  141. compute_api_client/api/batch_runs_api.py +0 -862
  142. compute_api_client/api/runs_api.py +0 -723
  143. compute_api_client/api/runtime_api.py +0 -449
  144. compute_api_client/api/runtime_types_api.py +0 -303
  145. compute_api_client/docs/BatchRun.md +0 -21
  146. compute_api_client/docs/BatchRunIn.md +0 -12
  147. compute_api_client/docs/Run.md +0 -19
  148. compute_api_client/docs/RunIn.md +0 -14
  149. compute_api_client/docs/Runtime.md +0 -16
  150. compute_api_client/docs/RuntimeApi.md +0 -229
  151. compute_api_client/docs/RuntimeType.md +0 -19
  152. compute_api_client/docs/RuntimeWithAuthentication.md +0 -17
  153. compute_api_client/models/batch_run.py +0 -423
  154. compute_api_client/models/batch_run_in.py +0 -171
  155. compute_api_client/models/batch_run_status.py +0 -114
  156. compute_api_client/models/run.py +0 -376
  157. compute_api_client/models/run_in.py +0 -233
  158. compute_api_client/models/run_status.py +0 -114
  159. compute_api_client/models/runtime.py +0 -290
  160. compute_api_client/models/runtime_status.py +0 -113
  161. compute_api_client/models/runtime_type.py +0 -357
  162. compute_api_client/models/runtime_with_authentication.py +0 -320
  163. qi_compute_api_client-0.7.0.dist-info/RECORD +0 -137
  164. {qi_compute_api_client-0.7.0.dist-info → qi_compute_api_client-0.17.0.dist-info}/LICENSE.md +0 -0
  165. {qi_compute_api_client-0.7.0.dist-info → qi_compute_api_client-0.17.0.dist-info}/WHEEL +0 -0
@@ -1,36 +1,45 @@
1
1
  # coding: utf-8
2
+
2
3
  """
3
4
  Quantum Inspire 2
4
5
 
5
- No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) # noqa: E501
6
+ No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
6
7
 
7
8
  The version of the OpenAPI document: 0.1.0
8
- Generated by: https://openapi-generator.tech
9
- """
9
+ Generated by OpenAPI Generator (https://openapi-generator.tech)
10
+
11
+ Do not edit the class manually.
12
+ """ # noqa: E501
10
13
 
11
- from __future__ import absolute_import
12
14
 
13
15
  import atexit
14
16
  import datetime
15
17
  from dateutil.parser import parse
16
18
  import json
17
19
  import mimetypes
18
- from multiprocessing.pool import ThreadPool
19
20
  import os
20
21
  import re
21
22
  import tempfile
22
23
 
23
- # python 2 and python 3 compatibility library
24
- import six
25
- from six.moves.urllib.parse import quote
24
+ from urllib.parse import quote
25
+ from typing import Tuple, Optional, List
26
26
 
27
27
  from compute_api_client.configuration import Configuration
28
+ from compute_api_client.api_response import ApiResponse
28
29
  import compute_api_client.models
29
30
  from compute_api_client import rest
30
- from compute_api_client.exceptions import ApiValueError, ApiException
31
-
32
-
33
- class ApiClient(object):
31
+ from compute_api_client.exceptions import (
32
+ ApiValueError,
33
+ ApiException,
34
+ BadRequestException,
35
+ UnauthorizedException,
36
+ ForbiddenException,
37
+ NotFoundException,
38
+ ServiceException
39
+ )
40
+
41
+
42
+ class ApiClient:
34
43
  """Generic API client for OpenAPI client library builds.
35
44
 
36
45
  OpenAPI generic API client. This client handles the client-
@@ -38,24 +47,18 @@ class ApiClient(object):
38
47
  the methods and models for each application are generated from the OpenAPI
39
48
  templates.
40
49
 
41
- NOTE: This class is auto generated by OpenAPI Generator.
42
- Ref: https://openapi-generator.tech
43
- Do not edit the class manually.
44
-
45
50
  :param configuration: .Configuration object for this client
46
51
  :param header_name: a header to pass when making calls to the API.
47
52
  :param header_value: a header value to pass when making calls to
48
53
  the API.
49
54
  :param cookie: a cookie to include in the header when making calls
50
55
  to the API
51
- :param pool_threads: The number of threads to use for async requests
52
- to the API. More threads means more concurrent API requests.
53
56
  """
54
57
 
55
- PRIMITIVE_TYPES = (float, bool, bytes, six.text_type) + six.integer_types
58
+ PRIMITIVE_TYPES = (float, bool, bytes, str, int)
56
59
  NATIVE_TYPES_MAPPING = {
57
60
  'int': int,
58
- 'long': int if six.PY3 else long, # noqa: F821
61
+ 'long': int, # TODO remove as only py3 is supported?
59
62
  'float': float,
60
63
  'str': str,
61
64
  'bool': bool,
@@ -65,12 +68,17 @@ class ApiClient(object):
65
68
  }
66
69
  _pool = None
67
70
 
68
- def __init__(self, configuration=None, header_name=None, header_value=None,
69
- cookie=None, pool_threads=1):
71
+ def __init__(
72
+ self,
73
+ configuration=None,
74
+ header_name=None,
75
+ header_value=None,
76
+ cookie=None
77
+ ) -> None:
78
+ # use default configuration if none is provided
70
79
  if configuration is None:
71
- configuration = Configuration.get_default_copy()
80
+ configuration = Configuration.get_default()
72
81
  self.configuration = configuration
73
- self.pool_threads = pool_threads
74
82
 
75
83
  self.rest_client = rest.RESTClientObject(configuration)
76
84
  self.default_headers = {}
@@ -89,22 +97,6 @@ class ApiClient(object):
89
97
 
90
98
  async def close(self):
91
99
  await self.rest_client.close()
92
- if self._pool:
93
- self._pool.close()
94
- self._pool.join()
95
- self._pool = None
96
- if hasattr(atexit, 'unregister'):
97
- atexit.unregister(self.close)
98
-
99
- @property
100
- def pool(self):
101
- """Create thread pool on first request
102
- avoids instantiating unused threadpool for blocking clients.
103
- """
104
- if self._pool is None:
105
- atexit.register(self.close)
106
- self._pool = ThreadPool(self.pool_threads)
107
- return self._pool
108
100
 
109
101
  @property
110
102
  def user_agent(self):
@@ -118,13 +110,69 @@ class ApiClient(object):
118
110
  def set_default_header(self, header_name, header_value):
119
111
  self.default_headers[header_name] = header_value
120
112
 
121
- async def __call_api(
122
- self, resource_path, method, path_params=None,
123
- query_params=None, header_params=None, body=None, post_params=None,
124
- files=None, response_types_map=None, auth_settings=None,
125
- _return_http_data_only=None, collection_formats=None,
126
- _preload_content=True, _request_timeout=None, _host=None,
127
- _request_auth=None):
113
+
114
+ _default = None
115
+
116
+ @classmethod
117
+ def get_default(cls):
118
+ """Return new instance of ApiClient.
119
+
120
+ This method returns newly created, based on default constructor,
121
+ object of ApiClient class or returns a copy of default
122
+ ApiClient.
123
+
124
+ :return: The ApiClient object.
125
+ """
126
+ if cls._default is None:
127
+ cls._default = ApiClient()
128
+ return cls._default
129
+
130
+ @classmethod
131
+ def set_default(cls, default):
132
+ """Set default instance of ApiClient.
133
+
134
+ It stores default ApiClient.
135
+
136
+ :param default: object of ApiClient.
137
+ """
138
+ cls._default = default
139
+
140
+ def param_serialize(
141
+ self,
142
+ method,
143
+ resource_path,
144
+ path_params=None,
145
+ query_params=None,
146
+ header_params=None,
147
+ body=None,
148
+ post_params=None,
149
+ files=None, auth_settings=None,
150
+ collection_formats=None,
151
+ _host=None,
152
+ _request_auth=None
153
+ ) -> Tuple:
154
+
155
+ """Builds the HTTP request params needed by the request.
156
+ :param method: Method to call.
157
+ :param resource_path: Path to method endpoint.
158
+ :param path_params: Path parameters in the url.
159
+ :param query_params: Query parameters in the url.
160
+ :param header_params: Header parameters to be
161
+ placed in the request header.
162
+ :param body: Request body.
163
+ :param post_params dict: Request post form parameters,
164
+ for `application/x-www-form-urlencoded`, `multipart/form-data`.
165
+ :param auth_settings list: Auth Settings names for the request.
166
+ :param files dict: key -> filename, value -> filepath,
167
+ for `multipart/form-data`.
168
+ :param collection_formats: dict of collection formats for path, query,
169
+ header, and post parameters.
170
+ :param _request_auth: set to override the auth_settings for an a single
171
+ request; this effectively ignores the authentication
172
+ in the spec for a single request.
173
+ :return: tuple of form (path, http_method, query_params, header_params,
174
+ body, post_params, files)
175
+ """
128
176
 
129
177
  config = self.configuration
130
178
 
@@ -135,14 +183,17 @@ class ApiClient(object):
135
183
  header_params['Cookie'] = self.cookie
136
184
  if header_params:
137
185
  header_params = self.sanitize_for_serialization(header_params)
138
- header_params = dict(self.parameters_to_tuples(header_params,
139
- collection_formats))
186
+ header_params = dict(
187
+ self.parameters_to_tuples(header_params,collection_formats)
188
+ )
140
189
 
141
190
  # path parameters
142
191
  if path_params:
143
192
  path_params = self.sanitize_for_serialization(path_params)
144
- path_params = self.parameters_to_tuples(path_params,
145
- collection_formats)
193
+ path_params = self.parameters_to_tuples(
194
+ path_params,
195
+ collection_formats
196
+ )
146
197
  for k, v in path_params:
147
198
  # specified safe chars, encode everything
148
199
  resource_path = resource_path.replace(
@@ -150,24 +201,26 @@ class ApiClient(object):
150
201
  quote(str(v), safe=config.safe_chars_for_path_param)
151
202
  )
152
203
 
153
- # query parameters
154
- if query_params:
155
- query_params = self.sanitize_for_serialization(query_params)
156
- query_params = self.parameters_to_tuples(query_params,
157
- collection_formats)
158
-
159
204
  # post parameters
160
205
  if post_params or files:
161
206
  post_params = post_params if post_params else []
162
207
  post_params = self.sanitize_for_serialization(post_params)
163
- post_params = self.parameters_to_tuples(post_params,
164
- collection_formats)
208
+ post_params = self.parameters_to_tuples(
209
+ post_params,
210
+ collection_formats
211
+ )
165
212
  post_params.extend(self.files_parameters(files))
166
213
 
167
214
  # auth setting
168
215
  self.update_params_for_auth(
169
- header_params, query_params, auth_settings,
170
- request_auth=_request_auth)
216
+ header_params,
217
+ query_params,
218
+ auth_settings,
219
+ resource_path,
220
+ method,
221
+ body,
222
+ request_auth=_request_auth
223
+ )
171
224
 
172
225
  # body
173
226
  if body:
@@ -180,46 +233,112 @@ class ApiClient(object):
180
233
  # use server/host defined in path or operation instead
181
234
  url = _host + resource_path
182
235
 
236
+ # query parameters
237
+ if query_params:
238
+ query_params = self.sanitize_for_serialization(query_params)
239
+ url_query = self.parameters_to_url_query(
240
+ query_params,
241
+ collection_formats
242
+ )
243
+ url += "?" + url_query
244
+
245
+ return method, url, header_params, body, post_params
246
+
247
+
248
+ async def call_api(
249
+ self,
250
+ method,
251
+ url,
252
+ header_params=None,
253
+ body=None,
254
+ post_params=None,
255
+ _request_timeout=None
256
+ ) -> rest.RESTResponse:
257
+ """Makes the HTTP request (synchronous)
258
+ :param method: Method to call.
259
+ :param url: Path to method endpoint.
260
+ :param header_params: Header parameters to be
261
+ placed in the request header.
262
+ :param body: Request body.
263
+ :param post_params dict: Request post form parameters,
264
+ for `application/x-www-form-urlencoded`, `multipart/form-data`.
265
+ :param _request_timeout: timeout setting for this request.
266
+ :return: RESTResponse
267
+ """
268
+
183
269
  try:
184
270
  # perform request and return response
185
- response_data = await self.request(
186
- method, url, query_params=query_params, headers=header_params,
187
- post_params=post_params, body=body,
188
- _preload_content=_preload_content,
189
- _request_timeout=_request_timeout)
271
+ response_data = await self.rest_client.request(
272
+ method, url,
273
+ headers=header_params,
274
+ body=body, post_params=post_params,
275
+ _request_timeout=_request_timeout
276
+ )
277
+
190
278
  except ApiException as e:
191
- e.body = e.body.decode('utf-8') if six.PY3 else e.body
279
+ if e.body:
280
+ e.body = e.body.decode('utf-8')
192
281
  raise e
193
282
 
194
- self.last_response = response_data
283
+ return response_data
284
+
285
+ def response_deserialize(
286
+ self,
287
+ response_data=None,
288
+ response_types_map=None
289
+ ) -> ApiResponse:
290
+ """Deserializes response into an object.
291
+ :param response_data: RESTResponse object to be deserialized.
292
+ :param response_types_map: dict of response types.
293
+ :return: ApiResponse
294
+ """
295
+
195
296
 
196
- return_data = response_data
297
+ response_type = response_types_map.get(str(response_data.status), None)
298
+ if not response_type and isinstance(response_data.status, int) and 100 <= response_data.status <= 599:
299
+ # if not found, look for '1XX', '2XX', etc.
300
+ response_type = response_types_map.get(str(response_data.status)[0] + "XX", None)
197
301
 
198
- if not _preload_content:
199
- return return_data
302
+ if not 200 <= response_data.status <= 299:
303
+ if response_data.status == 400:
304
+ raise BadRequestException(http_resp=response_data)
200
305
 
201
- response_type = response_types_map.get(response_data.status, None)
306
+ if response_data.status == 401:
307
+ raise UnauthorizedException(http_resp=response_data)
202
308
 
203
- if six.PY3 and response_type not in ["file", "bytes"]:
204
- match = None
205
- content_type = response_data.getheader('content-type')
206
- if content_type is not None:
207
- match = re.search(r"charset=([a-zA-Z\-\d]+)[\s\;]?", content_type)
208
- encoding = match.group(1) if match else "utf-8"
209
- response_data.data = response_data.data.decode(encoding)
309
+ if response_data.status == 403:
310
+ raise ForbiddenException(http_resp=response_data)
311
+
312
+ if response_data.status == 404:
313
+ raise NotFoundException(http_resp=response_data)
314
+
315
+ if 500 <= response_data.status <= 599:
316
+ raise ServiceException(http_resp=response_data)
317
+ raise ApiException(http_resp=response_data)
210
318
 
211
319
  # deserialize response data
212
320
 
213
- if response_type:
214
- return_data = self.deserialize(response_data, response_type)
215
- else:
321
+ if response_type == "bytearray":
322
+ return_data = response_data.data
323
+ elif response_type is None:
216
324
  return_data = None
217
-
218
- if _return_http_data_only:
219
- return (return_data)
325
+ elif response_type == "file":
326
+ return_data = self.__deserialize_file(response_data)
220
327
  else:
221
- return (return_data, response_data.status,
222
- response_data.getheaders())
328
+ match = None
329
+ content_type = response_data.getheader('content-type')
330
+ if content_type is not None:
331
+ match = re.search(r"charset=([a-zA-Z\-\d]+)[\s;]?", content_type)
332
+ encoding = match.group(1) if match else "utf-8"
333
+ response_text = response_data.data.decode(encoding)
334
+ return_data = self.deserialize(response_text, response_type)
335
+
336
+ return ApiResponse(
337
+ status_code = response_data.status,
338
+ data = return_data,
339
+ headers = response_data.getheaders(),
340
+ raw_data = response_data.data
341
+ )
223
342
 
224
343
  def sanitize_for_serialization(self, obj):
225
344
  """Builds a JSON POST object.
@@ -240,15 +359,17 @@ class ApiClient(object):
240
359
  elif isinstance(obj, self.PRIMITIVE_TYPES):
241
360
  return obj
242
361
  elif isinstance(obj, list):
243
- return [self.sanitize_for_serialization(sub_obj)
244
- for sub_obj in obj]
362
+ return [
363
+ self.sanitize_for_serialization(sub_obj) for sub_obj in obj
364
+ ]
245
365
  elif isinstance(obj, tuple):
246
- return tuple(self.sanitize_for_serialization(sub_obj)
247
- for sub_obj in obj)
366
+ return tuple(
367
+ self.sanitize_for_serialization(sub_obj) for sub_obj in obj
368
+ )
248
369
  elif isinstance(obj, (datetime.datetime, datetime.date)):
249
370
  return obj.isoformat()
250
371
 
251
- if isinstance(obj, dict):
372
+ elif isinstance(obj, dict):
252
373
  obj_dict = obj
253
374
  else:
254
375
  # Convert model obj to dict except
@@ -256,14 +377,14 @@ class ApiClient(object):
256
377
  # and attributes which value is not None.
257
378
  # Convert attribute name to json key in
258
379
  # model definition for request.
259
- obj_dict = {obj.attribute_map[attr]: getattr(obj, attr)
260
- for attr, _ in six.iteritems(obj.openapi_types)
261
- if getattr(obj, attr) is not None}
380
+ obj_dict = obj.to_dict()
262
381
 
263
- return {key: self.sanitize_for_serialization(val)
264
- for key, val in six.iteritems(obj_dict)}
382
+ return {
383
+ key: self.sanitize_for_serialization(val)
384
+ for key, val in obj_dict.items()
385
+ }
265
386
 
266
- def deserialize(self, response, response_type):
387
+ def deserialize(self, response_text, response_type):
267
388
  """Deserializes response into an object.
268
389
 
269
390
  :param response: RESTResponse object to be deserialized.
@@ -272,16 +393,12 @@ class ApiClient(object):
272
393
 
273
394
  :return: deserialized object.
274
395
  """
275
- # handle file downloading
276
- # save response body into a tmp file and return the instance
277
- if response_type == "file":
278
- return self.__deserialize_file(response)
279
396
 
280
397
  # fetch data from response object
281
398
  try:
282
- data = json.loads(response.data)
399
+ data = json.loads(response_text)
283
400
  except ValueError:
284
- data = response.data
401
+ data = response_text
285
402
 
286
403
  return self.__deserialize(data, response_type)
287
404
 
@@ -296,16 +413,16 @@ class ApiClient(object):
296
413
  if data is None:
297
414
  return None
298
415
 
299
- if type(klass) == str:
300
- if klass.startswith('list['):
301
- sub_kls = re.match(r'list\[(.*)\]', klass).group(1)
416
+ if isinstance(klass, str):
417
+ if klass.startswith('List['):
418
+ sub_kls = re.match(r'List\[(.*)]', klass).group(1)
302
419
  return [self.__deserialize(sub_data, sub_kls)
303
420
  for sub_data in data]
304
421
 
305
- if klass.startswith('dict['):
306
- sub_kls = re.match(r'dict\[([^,]*), (.*)\]', klass).group(2)
422
+ if klass.startswith('Dict['):
423
+ sub_kls = re.match(r'Dict\[([^,]*), (.*)]', klass).group(2)
307
424
  return {k: self.__deserialize(v, sub_kls)
308
- for k, v in six.iteritems(data)}
425
+ for k, v in data.items()}
309
426
 
310
427
  # convert str to class
311
428
  if klass in self.NATIVE_TYPES_MAPPING:
@@ -324,134 +441,6 @@ class ApiClient(object):
324
441
  else:
325
442
  return self.__deserialize_model(data, klass)
326
443
 
327
- def call_api(self, resource_path, method,
328
- path_params=None, query_params=None, header_params=None,
329
- body=None, post_params=None, files=None,
330
- response_types_map=None, auth_settings=None,
331
- async_req=None, _return_http_data_only=None,
332
- collection_formats=None,_preload_content=True,
333
- _request_timeout=None, _host=None, _request_auth=None):
334
- """Makes the HTTP request (synchronous) and returns deserialized data.
335
-
336
- To make an async_req request, set the async_req parameter.
337
-
338
- :param resource_path: Path to method endpoint.
339
- :param method: Method to call.
340
- :param path_params: Path parameters in the url.
341
- :param query_params: Query parameters in the url.
342
- :param header_params: Header parameters to be
343
- placed in the request header.
344
- :param body: Request body.
345
- :param post_params dict: Request post form parameters,
346
- for `application/x-www-form-urlencoded`, `multipart/form-data`.
347
- :param auth_settings list: Auth Settings names for the request.
348
- :param response: Response data type.
349
- :param files dict: key -> filename, value -> filepath,
350
- for `multipart/form-data`.
351
- :param async_req bool: execute request asynchronously
352
- :param _return_http_data_only: response data without head status code
353
- and headers
354
- :param collection_formats: dict of collection formats for path, query,
355
- header, and post parameters.
356
- :param _preload_content: if False, the urllib3.HTTPResponse object will
357
- be returned without reading/decoding response
358
- data. Default is True.
359
- :param _request_timeout: timeout setting for this request. If one
360
- number provided, it will be total request
361
- timeout. It can also be a pair (tuple) of
362
- (connection, read) timeouts.
363
- :param _request_auth: set to override the auth_settings for an a single
364
- request; this effectively ignores the authentication
365
- in the spec for a single request.
366
- :type _request_token: dict, optional
367
- :return:
368
- If async_req parameter is True,
369
- the request will be called asynchronously.
370
- The method will return the request thread.
371
- If parameter async_req is False or missing,
372
- then the method will return the response directly.
373
- """
374
- if not async_req:
375
- return self.__call_api(resource_path, method,
376
- path_params, query_params, header_params,
377
- body, post_params, files,
378
- response_types_map, auth_settings,
379
- _return_http_data_only, collection_formats,
380
- _preload_content, _request_timeout, _host,
381
- _request_auth)
382
-
383
- return self.pool.apply_async(self.__call_api, (resource_path,
384
- method, path_params,
385
- query_params,
386
- header_params, body,
387
- post_params, files,
388
- response_types_map,
389
- auth_settings,
390
- _return_http_data_only,
391
- collection_formats,
392
- _preload_content,
393
- _request_timeout,
394
- _host, _request_auth))
395
-
396
- def request(self, method, url, query_params=None, headers=None,
397
- post_params=None, body=None, _preload_content=True,
398
- _request_timeout=None):
399
- """Makes the HTTP request using RESTClient."""
400
- if method == "GET":
401
- return self.rest_client.GET(url,
402
- query_params=query_params,
403
- _preload_content=_preload_content,
404
- _request_timeout=_request_timeout,
405
- headers=headers)
406
- elif method == "HEAD":
407
- return self.rest_client.HEAD(url,
408
- query_params=query_params,
409
- _preload_content=_preload_content,
410
- _request_timeout=_request_timeout,
411
- headers=headers)
412
- elif method == "OPTIONS":
413
- return self.rest_client.OPTIONS(url,
414
- query_params=query_params,
415
- headers=headers,
416
- _preload_content=_preload_content,
417
- _request_timeout=_request_timeout)
418
- elif method == "POST":
419
- return self.rest_client.POST(url,
420
- query_params=query_params,
421
- headers=headers,
422
- post_params=post_params,
423
- _preload_content=_preload_content,
424
- _request_timeout=_request_timeout,
425
- body=body)
426
- elif method == "PUT":
427
- return self.rest_client.PUT(url,
428
- query_params=query_params,
429
- headers=headers,
430
- post_params=post_params,
431
- _preload_content=_preload_content,
432
- _request_timeout=_request_timeout,
433
- body=body)
434
- elif method == "PATCH":
435
- return self.rest_client.PATCH(url,
436
- query_params=query_params,
437
- headers=headers,
438
- post_params=post_params,
439
- _preload_content=_preload_content,
440
- _request_timeout=_request_timeout,
441
- body=body)
442
- elif method == "DELETE":
443
- return self.rest_client.DELETE(url,
444
- query_params=query_params,
445
- headers=headers,
446
- _preload_content=_preload_content,
447
- _request_timeout=_request_timeout,
448
- body=body)
449
- else:
450
- raise ApiValueError(
451
- "http method must be `GET`, `HEAD`, `OPTIONS`,"
452
- " `POST`, `PATCH`, `PUT` or `DELETE`."
453
- )
454
-
455
444
  def parameters_to_tuples(self, params, collection_formats):
456
445
  """Get parameters as list of tuples, formatting collections.
457
446
 
@@ -462,7 +451,7 @@ class ApiClient(object):
462
451
  new_params = []
463
452
  if collection_formats is None:
464
453
  collection_formats = {}
465
- for k, v in six.iteritems(params) if isinstance(params, dict) else params: # noqa: E501
454
+ for k, v in params.items() if isinstance(params, dict) else params:
466
455
  if k in collection_formats:
467
456
  collection_format = collection_formats[k]
468
457
  if collection_format == 'multi':
@@ -482,6 +471,45 @@ class ApiClient(object):
482
471
  new_params.append((k, v))
483
472
  return new_params
484
473
 
474
+ def parameters_to_url_query(self, params, collection_formats):
475
+ """Get parameters as list of tuples, formatting collections.
476
+
477
+ :param params: Parameters as dict or list of two-tuples
478
+ :param dict collection_formats: Parameter collection formats
479
+ :return: URL query string (e.g. a=Hello%20World&b=123)
480
+ """
481
+ new_params = []
482
+ if collection_formats is None:
483
+ collection_formats = {}
484
+ for k, v in params.items() if isinstance(params, dict) else params:
485
+ if isinstance(v, bool):
486
+ v = str(v).lower()
487
+ if isinstance(v, (int, float)):
488
+ v = str(v)
489
+ if isinstance(v, dict):
490
+ v = json.dumps(v)
491
+
492
+ if k in collection_formats:
493
+ collection_format = collection_formats[k]
494
+ if collection_format == 'multi':
495
+ new_params.extend((k, value) for value in v)
496
+ else:
497
+ if collection_format == 'ssv':
498
+ delimiter = ' '
499
+ elif collection_format == 'tsv':
500
+ delimiter = '\t'
501
+ elif collection_format == 'pipes':
502
+ delimiter = '|'
503
+ else: # csv is the default
504
+ delimiter = ','
505
+ new_params.append(
506
+ (k, delimiter.join(quote(str(value)) for value in v))
507
+ )
508
+ else:
509
+ new_params.append((k, quote(str(v))))
510
+
511
+ return "&".join(["=".join(item) for item in new_params])
512
+
485
513
  def files_parameters(self, files=None):
486
514
  """Builds form parameters.
487
515
 
@@ -491,7 +519,7 @@ class ApiClient(object):
491
519
  params = []
492
520
 
493
521
  if files:
494
- for k, v in six.iteritems(files):
522
+ for k, v in files.items():
495
523
  if not v:
496
524
  continue
497
525
  file_names = v if type(v) is list else [v]
@@ -499,59 +527,65 @@ class ApiClient(object):
499
527
  with open(n, 'rb') as f:
500
528
  filename = os.path.basename(f.name)
501
529
  filedata = f.read()
502
- mimetype = (mimetypes.guess_type(filename)[0] or
503
- 'application/octet-stream')
530
+ mimetype = (
531
+ mimetypes.guess_type(filename)[0]
532
+ or 'application/octet-stream'
533
+ )
504
534
  params.append(
505
- tuple([k, tuple([filename, filedata, mimetype])]))
535
+ tuple([k, tuple([filename, filedata, mimetype])])
536
+ )
506
537
 
507
538
  return params
508
539
 
509
- def select_header_accept(self, accepts):
540
+ def select_header_accept(self, accepts: List[str]) -> Optional[str]:
510
541
  """Returns `Accept` based on an array of accepts provided.
511
542
 
512
543
  :param accepts: List of headers.
513
544
  :return: Accept (e.g. application/json).
514
545
  """
515
546
  if not accepts:
516
- return
547
+ return None
517
548
 
518
- accepts = [x.lower() for x in accepts]
549
+ for accept in accepts:
550
+ if re.search('json', accept, re.IGNORECASE):
551
+ return accept
519
552
 
520
- if 'application/json' in accepts:
521
- return 'application/json'
522
- else:
523
- return ', '.join(accepts)
553
+ return accepts[0]
524
554
 
525
- def select_header_content_type(self, content_types, method=None, body=None):
555
+ def select_header_content_type(self, content_types):
526
556
  """Returns `Content-Type` based on an array of content_types provided.
527
557
 
528
558
  :param content_types: List of content-types.
529
- :param method: http method (e.g. POST, PATCH).
530
- :param body: http body to send.
531
559
  :return: Content-Type (e.g. application/json).
532
560
  """
533
561
  if not content_types:
534
562
  return None
535
563
 
536
- content_types = [x.lower() for x in content_types]
537
-
538
- if (method == 'PATCH' and
539
- 'application/json-patch+json' in content_types and
540
- isinstance(body, list)):
541
- return 'application/json-patch+json'
542
-
543
- if 'application/json' in content_types or '*/*' in content_types:
544
- return 'application/json'
545
- else:
546
- return content_types[0]
547
-
548
- def update_params_for_auth(self, headers, queries, auth_settings,
549
- request_auth=None):
564
+ for content_type in content_types:
565
+ if re.search('json', content_type, re.IGNORECASE):
566
+ return content_type
567
+
568
+ return content_types[0]
569
+
570
+ def update_params_for_auth(
571
+ self,
572
+ headers,
573
+ queries,
574
+ auth_settings,
575
+ resource_path,
576
+ method,
577
+ body,
578
+ request_auth=None
579
+ ) -> None:
550
580
  """Updates header and query params based on authentication setting.
551
581
 
552
582
  :param headers: Header parameters dict to be updated.
553
583
  :param queries: Query parameters tuple list to be updated.
554
584
  :param auth_settings: Authentication setting identifiers list.
585
+ :resource_path: A string representation of the HTTP request resource path.
586
+ :method: A string representation of the HTTP request method.
587
+ :body: A object representing the body of the HTTP request.
588
+ The object type is the return value of sanitize_for_serialization().
555
589
  :param request_auth: if set, the provided settings will
556
590
  override the token in the configuration.
557
591
  """
@@ -559,25 +593,51 @@ class ApiClient(object):
559
593
  return
560
594
 
561
595
  if request_auth:
562
- self._apply_auth_params(headers, queries, request_auth)
563
- return
564
-
565
- for auth in auth_settings:
566
- auth_setting = self.configuration.auth_settings().get(auth)
567
- if auth_setting:
568
- self._apply_auth_params(headers, queries, auth_setting)
569
-
570
- def _apply_auth_params(self, headers, queries, auth_setting):
596
+ self._apply_auth_params(
597
+ headers,
598
+ queries,
599
+ resource_path,
600
+ method,
601
+ body,
602
+ request_auth
603
+ )
604
+ else:
605
+ for auth in auth_settings:
606
+ auth_setting = self.configuration.auth_settings().get(auth)
607
+ if auth_setting:
608
+ self._apply_auth_params(
609
+ headers,
610
+ queries,
611
+ resource_path,
612
+ method,
613
+ body,
614
+ auth_setting
615
+ )
616
+
617
+ def _apply_auth_params(
618
+ self,
619
+ headers,
620
+ queries,
621
+ resource_path,
622
+ method,
623
+ body,
624
+ auth_setting
625
+ ) -> None:
571
626
  """Updates the request parameters based on a single auth_setting
572
627
 
573
628
  :param headers: Header parameters dict to be updated.
574
629
  :param queries: Query parameters tuple list to be updated.
630
+ :resource_path: A string representation of the HTTP request resource path.
631
+ :method: A string representation of the HTTP request method.
632
+ :body: A object representing the body of the HTTP request.
633
+ The object type is the return value of sanitize_for_serialization().
575
634
  :param auth_setting: auth settings for the endpoint
576
635
  """
577
636
  if auth_setting['in'] == 'cookie':
578
637
  headers['Cookie'] = auth_setting['value']
579
638
  elif auth_setting['in'] == 'header':
580
- headers[auth_setting['key']] = auth_setting['value']
639
+ if auth_setting['type'] != 'http-signature':
640
+ headers[auth_setting['key']] = auth_setting['value']
581
641
  elif auth_setting['in'] == 'query':
582
642
  queries.append((auth_setting['key'], auth_setting['value']))
583
643
  else:
@@ -591,6 +651,9 @@ class ApiClient(object):
591
651
  Saves response body into a file in a temporary folder,
592
652
  using the filename from the `Content-Disposition` header if provided.
593
653
 
654
+ handle file downloading
655
+ save response body into a tmp file and return the instance
656
+
594
657
  :param response: RESTResponse.
595
658
  :return: file path.
596
659
  """
@@ -600,8 +663,10 @@ class ApiClient(object):
600
663
 
601
664
  content_disposition = response.getheader("Content-Disposition")
602
665
  if content_disposition:
603
- filename = re.search(r'filename=[\'"]?([^\'"\s]+)[\'"]?',
604
- content_disposition).group(1)
666
+ filename = re.search(
667
+ r'filename=[\'"]?([^\'"\s]+)[\'"]?',
668
+ content_disposition
669
+ ).group(1)
605
670
  path = os.path.join(os.path.dirname(path), filename)
606
671
 
607
672
  with open(path, "wb") as f:
@@ -620,7 +685,7 @@ class ApiClient(object):
620
685
  try:
621
686
  return klass(data)
622
687
  except UnicodeEncodeError:
623
- return six.text_type(data)
688
+ return str(data)
624
689
  except TypeError:
625
690
  return data
626
691
 
@@ -675,28 +740,5 @@ class ApiClient(object):
675
740
  :param klass: class literal.
676
741
  :return: model object.
677
742
  """
678
- has_discriminator = False
679
- if (hasattr(klass, 'get_real_child_model')
680
- and klass.discriminator_value_class_map):
681
- has_discriminator = True
682
-
683
- if not klass.openapi_types and has_discriminator is False:
684
- return data
685
743
 
686
- kwargs = {}
687
- if (data is not None and
688
- klass.openapi_types is not None and
689
- isinstance(data, (list, dict))):
690
- for attr, attr_type in six.iteritems(klass.openapi_types):
691
- if klass.attribute_map[attr] in data:
692
- value = data[klass.attribute_map[attr]]
693
- kwargs[attr] = self.__deserialize(value, attr_type)
694
-
695
- kwargs["local_vars_configuration"] = self.configuration
696
- instance = klass(**kwargs)
697
-
698
- if has_discriminator:
699
- klass_name = instance.get_real_child_model(data)
700
- if klass_name:
701
- instance = self.__deserialize(data, klass_name)
702
- return instance
744
+ return klass.from_dict(data)