graphscope-flex 0.27.0__3-py2.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.
Files changed (77) hide show
  1. graphscope/flex/rest/__init__.py +97 -0
  2. graphscope/flex/rest/api/__init__.py +12 -0
  3. graphscope/flex/rest/api/alert_api.py +2780 -0
  4. graphscope/flex/rest/api/data_source_api.py +1173 -0
  5. graphscope/flex/rest/api/deployment_api.py +528 -0
  6. graphscope/flex/rest/api/graph_api.py +2803 -0
  7. graphscope/flex/rest/api/job_api.py +1356 -0
  8. graphscope/flex/rest/api/service_api.py +1311 -0
  9. graphscope/flex/rest/api/stored_procedure_api.py +1449 -0
  10. graphscope/flex/rest/api/utils_api.py +309 -0
  11. graphscope/flex/rest/api_client.py +759 -0
  12. graphscope/flex/rest/api_response.py +21 -0
  13. graphscope/flex/rest/configuration.py +437 -0
  14. graphscope/flex/rest/exceptions.py +200 -0
  15. graphscope/flex/rest/models/__init__.py +73 -0
  16. graphscope/flex/rest/models/base_edge_type.py +102 -0
  17. graphscope/flex/rest/models/base_edge_type_vertex_type_pair_relations_inner.py +105 -0
  18. graphscope/flex/rest/models/base_edge_type_vertex_type_pair_relations_inner_x_csr_params.py +98 -0
  19. graphscope/flex/rest/models/base_property_meta.py +105 -0
  20. graphscope/flex/rest/models/base_vertex_type.py +96 -0
  21. graphscope/flex/rest/models/base_vertex_type_x_csr_params.py +88 -0
  22. graphscope/flex/rest/models/column_mapping.py +94 -0
  23. graphscope/flex/rest/models/column_mapping_column.py +90 -0
  24. graphscope/flex/rest/models/create_alert_receiver_request.py +103 -0
  25. graphscope/flex/rest/models/create_alert_rule_request.py +112 -0
  26. graphscope/flex/rest/models/create_dataloading_job_response.py +88 -0
  27. graphscope/flex/rest/models/create_edge_type.py +114 -0
  28. graphscope/flex/rest/models/create_graph_request.py +106 -0
  29. graphscope/flex/rest/models/create_graph_response.py +88 -0
  30. graphscope/flex/rest/models/create_graph_schema_request.py +106 -0
  31. graphscope/flex/rest/models/create_property_meta.py +100 -0
  32. graphscope/flex/rest/models/create_stored_proc_request.py +101 -0
  33. graphscope/flex/rest/models/create_stored_proc_response.py +88 -0
  34. graphscope/flex/rest/models/create_vertex_type.py +108 -0
  35. graphscope/flex/rest/models/dataloading_job_config.py +136 -0
  36. graphscope/flex/rest/models/dataloading_job_config_edges_inner.py +92 -0
  37. graphscope/flex/rest/models/dataloading_job_config_loading_config.py +104 -0
  38. graphscope/flex/rest/models/dataloading_job_config_loading_config_format.py +90 -0
  39. graphscope/flex/rest/models/dataloading_job_config_vertices_inner.py +88 -0
  40. graphscope/flex/rest/models/edge_mapping.py +122 -0
  41. graphscope/flex/rest/models/edge_mapping_type_triplet.py +92 -0
  42. graphscope/flex/rest/models/error.py +90 -0
  43. graphscope/flex/rest/models/get_alert_message_response.py +123 -0
  44. graphscope/flex/rest/models/get_alert_receiver_response.py +107 -0
  45. graphscope/flex/rest/models/get_alert_rule_response.py +114 -0
  46. graphscope/flex/rest/models/get_edge_type.py +116 -0
  47. graphscope/flex/rest/models/get_graph_response.py +126 -0
  48. graphscope/flex/rest/models/get_graph_schema_response.py +106 -0
  49. graphscope/flex/rest/models/get_property_meta.py +102 -0
  50. graphscope/flex/rest/models/get_stored_proc_response.py +128 -0
  51. graphscope/flex/rest/models/get_vertex_type.py +110 -0
  52. graphscope/flex/rest/models/gs_data_type.py +138 -0
  53. graphscope/flex/rest/models/job_status.py +107 -0
  54. graphscope/flex/rest/models/long_text.py +93 -0
  55. graphscope/flex/rest/models/node_status.py +94 -0
  56. graphscope/flex/rest/models/parameter.py +94 -0
  57. graphscope/flex/rest/models/primitive_type.py +95 -0
  58. graphscope/flex/rest/models/running_deployment_info.py +128 -0
  59. graphscope/flex/rest/models/running_deployment_status.py +105 -0
  60. graphscope/flex/rest/models/running_deployment_status_nodes_inner.py +124 -0
  61. graphscope/flex/rest/models/schema_mapping.py +106 -0
  62. graphscope/flex/rest/models/service_status.py +105 -0
  63. graphscope/flex/rest/models/service_status_sdk_endpoints.py +94 -0
  64. graphscope/flex/rest/models/start_service_request.py +88 -0
  65. graphscope/flex/rest/models/stored_procedure_meta.py +124 -0
  66. graphscope/flex/rest/models/string_type.py +92 -0
  67. graphscope/flex/rest/models/string_type_string.py +124 -0
  68. graphscope/flex/rest/models/update_alert_message_status_request.py +97 -0
  69. graphscope/flex/rest/models/update_stored_proc_request.py +88 -0
  70. graphscope/flex/rest/models/upload_file_response.py +88 -0
  71. graphscope/flex/rest/models/vertex_mapping.py +100 -0
  72. graphscope/flex/rest/py.typed +0 -0
  73. graphscope/flex/rest/rest.py +256 -0
  74. graphscope_flex-0.27.0.dist-info/METADATA +17 -0
  75. graphscope_flex-0.27.0.dist-info/RECORD +77 -0
  76. graphscope_flex-0.27.0.dist-info/WHEEL +6 -0
  77. graphscope_flex-0.27.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,759 @@
1
+ # coding: utf-8
2
+
3
+ """
4
+ GraphScope FLEX HTTP SERVICE API
5
+
6
+ This is a specification for GraphScope FLEX HTTP service based on the OpenAPI 3.0 specification. You can find out more details about specification at [doc](https://swagger.io/specification/v3/). Some useful links: - [GraphScope Repository](https://github.com/alibaba/GraphScope) - [The Source API definition for GraphScope Interactive](https://github.com/GraphScope/portal/tree/main/httpservice)
7
+
8
+ The version of the OpenAPI document: 1.0.0
9
+ Contact: graphscope@alibaba-inc.com
10
+ Generated by OpenAPI Generator (https://openapi-generator.tech)
11
+
12
+ Do not edit the class manually.
13
+ """ # noqa: E501
14
+
15
+
16
+ import datetime
17
+ from dateutil.parser import parse
18
+ from enum import Enum
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
27
+
28
+ from graphscope.flex.rest.configuration import Configuration
29
+ from graphscope.flex.rest.api_response import ApiResponse, T as ApiResponseT
30
+ import graphscope.flex.rest.models
31
+ from graphscope.flex.rest import rest
32
+ from graphscope.flex.rest.exceptions import (
33
+ ApiValueError,
34
+ ApiException,
35
+ BadRequestException,
36
+ UnauthorizedException,
37
+ ForbiddenException,
38
+ NotFoundException,
39
+ ServiceException
40
+ )
41
+
42
+ RequestSerialized = Tuple[str, str, Dict[str, str], Optional[str], List[str]]
43
+
44
+ class ApiClient:
45
+ """Generic API client for OpenAPI client library builds.
46
+
47
+ OpenAPI generic API client. This client handles the client-
48
+ server communication, and is invariant across implementations. Specifics of
49
+ the methods and models for each application are generated from the OpenAPI
50
+ templates.
51
+
52
+ :param configuration: .Configuration object for this client
53
+ :param header_name: a header to pass when making calls to the API.
54
+ :param header_value: a header value to pass when making calls to
55
+ the API.
56
+ :param cookie: a cookie to include in the header when making calls
57
+ to the API
58
+ """
59
+
60
+ PRIMITIVE_TYPES = (float, bool, bytes, str, int)
61
+ NATIVE_TYPES_MAPPING = {
62
+ 'int': int,
63
+ 'long': int, # TODO remove as only py3 is supported?
64
+ 'float': float,
65
+ 'str': str,
66
+ 'bool': bool,
67
+ 'date': datetime.date,
68
+ 'datetime': datetime.datetime,
69
+ 'object': object,
70
+ }
71
+ _pool = None
72
+
73
+ def __init__(
74
+ self,
75
+ configuration=None,
76
+ header_name=None,
77
+ header_value=None,
78
+ cookie=None
79
+ ) -> None:
80
+ # use default configuration if none is provided
81
+ if configuration is None:
82
+ configuration = Configuration.get_default()
83
+ self.configuration = configuration
84
+
85
+ self.rest_client = rest.RESTClientObject(configuration)
86
+ self.default_headers = {}
87
+ if header_name is not None:
88
+ self.default_headers[header_name] = header_value
89
+ self.cookie = cookie
90
+ # Set default User-Agent.
91
+ self.user_agent = 'OpenAPI-Generator/1.0.0/python'
92
+ self.client_side_validation = configuration.client_side_validation
93
+
94
+ def __enter__(self):
95
+ return self
96
+
97
+ def __exit__(self, exc_type, exc_value, traceback):
98
+ pass
99
+
100
+ @property
101
+ def user_agent(self):
102
+ """User agent for this API client"""
103
+ return self.default_headers['User-Agent']
104
+
105
+ @user_agent.setter
106
+ def user_agent(self, value):
107
+ self.default_headers['User-Agent'] = value
108
+
109
+ def set_default_header(self, header_name, header_value):
110
+ self.default_headers[header_name] = header_value
111
+
112
+
113
+ _default = None
114
+
115
+ @classmethod
116
+ def get_default(cls):
117
+ """Return new instance of ApiClient.
118
+
119
+ This method returns newly created, based on default constructor,
120
+ object of ApiClient class or returns a copy of default
121
+ ApiClient.
122
+
123
+ :return: The ApiClient object.
124
+ """
125
+ if cls._default is None:
126
+ cls._default = ApiClient()
127
+ return cls._default
128
+
129
+ @classmethod
130
+ def set_default(cls, default):
131
+ """Set default instance of ApiClient.
132
+
133
+ It stores default ApiClient.
134
+
135
+ :param default: object of ApiClient.
136
+ """
137
+ cls._default = default
138
+
139
+ def param_serialize(
140
+ self,
141
+ method,
142
+ resource_path,
143
+ path_params=None,
144
+ query_params=None,
145
+ header_params=None,
146
+ body=None,
147
+ post_params=None,
148
+ files=None, auth_settings=None,
149
+ collection_formats=None,
150
+ _host=None,
151
+ _request_auth=None
152
+ ) -> RequestSerialized:
153
+
154
+ """Builds the HTTP request params needed by the request.
155
+ :param method: Method to call.
156
+ :param resource_path: Path to method endpoint.
157
+ :param path_params: Path parameters in the url.
158
+ :param query_params: Query parameters in the url.
159
+ :param header_params: Header parameters to be
160
+ placed in the request header.
161
+ :param body: Request body.
162
+ :param post_params dict: Request post form parameters,
163
+ for `application/x-www-form-urlencoded`, `multipart/form-data`.
164
+ :param auth_settings list: Auth Settings names for the request.
165
+ :param files dict: key -> filename, value -> filepath,
166
+ for `multipart/form-data`.
167
+ :param collection_formats: dict of collection formats for path, query,
168
+ header, and post parameters.
169
+ :param _request_auth: set to override the auth_settings for an a single
170
+ request; this effectively ignores the authentication
171
+ in the spec for a single request.
172
+ :return: tuple of form (path, http_method, query_params, header_params,
173
+ body, post_params, files)
174
+ """
175
+
176
+ config = self.configuration
177
+
178
+ # header parameters
179
+ header_params = header_params or {}
180
+ header_params.update(self.default_headers)
181
+ if self.cookie:
182
+ header_params['Cookie'] = self.cookie
183
+ if header_params:
184
+ header_params = self.sanitize_for_serialization(header_params)
185
+ header_params = dict(
186
+ self.parameters_to_tuples(header_params,collection_formats)
187
+ )
188
+
189
+ # path parameters
190
+ if path_params:
191
+ path_params = self.sanitize_for_serialization(path_params)
192
+ path_params = self.parameters_to_tuples(
193
+ path_params,
194
+ collection_formats
195
+ )
196
+ for k, v in path_params:
197
+ # specified safe chars, encode everything
198
+ resource_path = resource_path.replace(
199
+ '{%s}' % k,
200
+ quote(str(v), safe=config.safe_chars_for_path_param)
201
+ )
202
+
203
+ # post parameters
204
+ if post_params or files:
205
+ post_params = post_params if post_params else []
206
+ post_params = self.sanitize_for_serialization(post_params)
207
+ post_params = self.parameters_to_tuples(
208
+ post_params,
209
+ collection_formats
210
+ )
211
+ post_params.extend(self.files_parameters(files))
212
+
213
+ # auth setting
214
+ self.update_params_for_auth(
215
+ header_params,
216
+ query_params,
217
+ auth_settings,
218
+ resource_path,
219
+ method,
220
+ body,
221
+ request_auth=_request_auth
222
+ )
223
+
224
+ # body
225
+ if body:
226
+ body = self.sanitize_for_serialization(body)
227
+
228
+ # request url
229
+ if _host is None:
230
+ url = self.configuration.host + resource_path
231
+ else:
232
+ # use server/host defined in path or operation instead
233
+ url = _host + resource_path
234
+
235
+ # query parameters
236
+ if query_params:
237
+ query_params = self.sanitize_for_serialization(query_params)
238
+ url_query = self.parameters_to_url_query(
239
+ query_params,
240
+ collection_formats
241
+ )
242
+ url += "?" + url_query
243
+
244
+ return method, url, header_params, body, post_params
245
+
246
+
247
+ def call_api(
248
+ self,
249
+ method,
250
+ url,
251
+ header_params=None,
252
+ body=None,
253
+ post_params=None,
254
+ _request_timeout=None
255
+ ) -> rest.RESTResponse:
256
+ """Makes the HTTP request (synchronous)
257
+ :param method: Method to call.
258
+ :param url: Path to method endpoint.
259
+ :param header_params: Header parameters to be
260
+ placed in the request header.
261
+ :param body: Request body.
262
+ :param post_params dict: Request post form parameters,
263
+ for `application/x-www-form-urlencoded`, `multipart/form-data`.
264
+ :param _request_timeout: timeout setting for this request.
265
+ :return: RESTResponse
266
+ """
267
+
268
+ try:
269
+ # perform request and return response
270
+ response_data = self.rest_client.request(
271
+ method, url,
272
+ headers=header_params,
273
+ body=body, post_params=post_params,
274
+ _request_timeout=_request_timeout
275
+ )
276
+
277
+ except ApiException as e:
278
+ raise e
279
+
280
+ return response_data
281
+
282
+ def response_deserialize(
283
+ self,
284
+ response_data: rest.RESTResponse,
285
+ response_types_map: Optional[Dict[str, ApiResponseT]]=None
286
+ ) -> ApiResponse[ApiResponseT]:
287
+ """Deserializes response into an object.
288
+ :param response_data: RESTResponse object to be deserialized.
289
+ :param response_types_map: dict of response types.
290
+ :return: ApiResponse
291
+ """
292
+
293
+ msg = "RESTResponse.read() must be called before passing it to response_deserialize()"
294
+ assert response_data.data is not None, msg
295
+
296
+ response_type = response_types_map.get(str(response_data.status), None)
297
+ if not response_type and isinstance(response_data.status, int) and 100 <= response_data.status <= 599:
298
+ # if not found, look for '1XX', '2XX', etc.
299
+ response_type = response_types_map.get(str(response_data.status)[0] + "XX", None)
300
+
301
+ # deserialize response data
302
+ response_text = None
303
+ return_data = None
304
+ try:
305
+ if response_type == "bytearray":
306
+ return_data = response_data.data
307
+ elif response_type == "file":
308
+ return_data = self.__deserialize_file(response_data)
309
+ elif response_type is not None:
310
+ match = None
311
+ content_type = response_data.getheader('content-type')
312
+ if content_type is not None:
313
+ match = re.search(r"charset=([a-zA-Z\-\d]+)[\s;]?", content_type)
314
+ encoding = match.group(1) if match else "utf-8"
315
+ response_text = response_data.data.decode(encoding)
316
+ return_data = self.deserialize(response_text, response_type)
317
+ finally:
318
+ if not 200 <= response_data.status <= 299:
319
+ raise ApiException.from_response(
320
+ http_resp=response_data,
321
+ body=response_text,
322
+ data=return_data,
323
+ )
324
+
325
+ return ApiResponse(
326
+ status_code = response_data.status,
327
+ data = return_data,
328
+ headers = response_data.getheaders(),
329
+ raw_data = response_data.data
330
+ )
331
+
332
+ def sanitize_for_serialization(self, obj):
333
+ """Builds a JSON POST object.
334
+
335
+ If obj is None, return None.
336
+ If obj is str, int, long, float, bool, return directly.
337
+ If obj is datetime.datetime, datetime.date
338
+ convert to string in iso8601 format.
339
+ If obj is list, sanitize each element in the list.
340
+ If obj is dict, return the dict.
341
+ If obj is OpenAPI model, return the properties dict.
342
+
343
+ :param obj: The data to serialize.
344
+ :return: The serialized form of data.
345
+ """
346
+ if obj is None:
347
+ return None
348
+ elif isinstance(obj, self.PRIMITIVE_TYPES):
349
+ return obj
350
+ elif isinstance(obj, list):
351
+ return [
352
+ self.sanitize_for_serialization(sub_obj) for sub_obj in obj
353
+ ]
354
+ elif isinstance(obj, tuple):
355
+ return tuple(
356
+ self.sanitize_for_serialization(sub_obj) for sub_obj in obj
357
+ )
358
+ elif isinstance(obj, (datetime.datetime, datetime.date)):
359
+ return obj.isoformat()
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
+ obj_dict = obj.to_dict()
370
+
371
+ return {
372
+ key: self.sanitize_for_serialization(val)
373
+ for key, val in obj_dict.items()
374
+ }
375
+
376
+ def deserialize(self, response_text, response_type):
377
+ """Deserializes response into an object.
378
+
379
+ :param response: RESTResponse object to be deserialized.
380
+ :param response_type: class literal for
381
+ deserialized object, or string of class name.
382
+
383
+ :return: deserialized object.
384
+ """
385
+
386
+ # fetch data from response object
387
+ try:
388
+ data = json.loads(response_text)
389
+ except ValueError:
390
+ data = response_text
391
+
392
+ return self.__deserialize(data, response_type)
393
+
394
+ def __deserialize(self, data, klass):
395
+ """Deserializes dict, list, str into an object.
396
+
397
+ :param data: dict, list or str.
398
+ :param klass: class literal, or string of class name.
399
+
400
+ :return: object.
401
+ """
402
+ if data is None:
403
+ return None
404
+
405
+ if isinstance(klass, str):
406
+ if klass.startswith('List['):
407
+ m = re.match(r'List\[(.*)]', klass)
408
+ assert m is not None, "Malformed List type definition"
409
+ sub_kls = m.group(1)
410
+ return [self.__deserialize(sub_data, sub_kls)
411
+ for sub_data in data]
412
+
413
+ if klass.startswith('Dict['):
414
+ m = re.match(r'Dict\[([^,]*), (.*)]', klass)
415
+ assert m is not None, "Malformed Dict type definition"
416
+ sub_kls = m.group(2)
417
+ return {k: self.__deserialize(v, sub_kls)
418
+ for k, v in data.items()}
419
+
420
+ # convert str to class
421
+ if klass in self.NATIVE_TYPES_MAPPING:
422
+ klass = self.NATIVE_TYPES_MAPPING[klass]
423
+ else:
424
+ klass = getattr(graphscope.flex.rest.models, klass)
425
+
426
+ if klass in self.PRIMITIVE_TYPES:
427
+ return self.__deserialize_primitive(data, klass)
428
+ elif klass == object:
429
+ return self.__deserialize_object(data)
430
+ elif klass == datetime.date:
431
+ return self.__deserialize_date(data)
432
+ elif klass == datetime.datetime:
433
+ return self.__deserialize_datetime(data)
434
+ elif issubclass(klass, Enum):
435
+ return self.__deserialize_enum(data, klass)
436
+ else:
437
+ return self.__deserialize_model(data, klass)
438
+
439
+ def parameters_to_tuples(self, params, collection_formats):
440
+ """Get parameters as list of tuples, formatting collections.
441
+
442
+ :param params: Parameters as dict or list of two-tuples
443
+ :param dict collection_formats: Parameter collection formats
444
+ :return: Parameters as list of tuples, collections formatted
445
+ """
446
+ new_params: List[Tuple[str, str]] = []
447
+ if collection_formats is None:
448
+ collection_formats = {}
449
+ for k, v in params.items() if isinstance(params, dict) else params:
450
+ if k in collection_formats:
451
+ collection_format = collection_formats[k]
452
+ if collection_format == 'multi':
453
+ new_params.extend((k, value) for value in v)
454
+ else:
455
+ if collection_format == 'ssv':
456
+ delimiter = ' '
457
+ elif collection_format == 'tsv':
458
+ delimiter = '\t'
459
+ elif collection_format == 'pipes':
460
+ delimiter = '|'
461
+ else: # csv is the default
462
+ delimiter = ','
463
+ new_params.append(
464
+ (k, delimiter.join(str(value) for value in v)))
465
+ else:
466
+ new_params.append((k, v))
467
+ return new_params
468
+
469
+ def parameters_to_url_query(self, params, collection_formats):
470
+ """Get parameters as list of tuples, formatting collections.
471
+
472
+ :param params: Parameters as dict or list of two-tuples
473
+ :param dict collection_formats: Parameter collection formats
474
+ :return: URL query string (e.g. a=Hello%20World&b=123)
475
+ """
476
+ new_params: List[Tuple[str, str]] = []
477
+ if collection_formats is None:
478
+ collection_formats = {}
479
+ for k, v in params.items() if isinstance(params, dict) else params:
480
+ if isinstance(v, bool):
481
+ v = str(v).lower()
482
+ if isinstance(v, (int, float)):
483
+ v = str(v)
484
+ if isinstance(v, dict):
485
+ v = json.dumps(v)
486
+
487
+ if k in collection_formats:
488
+ collection_format = collection_formats[k]
489
+ if collection_format == 'multi':
490
+ new_params.extend((k, str(value)) for value in v)
491
+ else:
492
+ if collection_format == 'ssv':
493
+ delimiter = ' '
494
+ elif collection_format == 'tsv':
495
+ delimiter = '\t'
496
+ elif collection_format == 'pipes':
497
+ delimiter = '|'
498
+ else: # csv is the default
499
+ delimiter = ','
500
+ new_params.append(
501
+ (k, delimiter.join(quote(str(value)) for value in v))
502
+ )
503
+ else:
504
+ new_params.append((k, quote(str(v))))
505
+
506
+ return "&".join(["=".join(map(str, item)) for item in new_params])
507
+
508
+ def files_parameters(self, files=None):
509
+ """Builds form parameters.
510
+
511
+ :param files: File parameters.
512
+ :return: Form parameters with files.
513
+ """
514
+ params = []
515
+
516
+ if files:
517
+ for k, v in files.items():
518
+ if not v:
519
+ continue
520
+ file_names = v if type(v) is list else [v]
521
+ for n in file_names:
522
+ with open(n, 'rb') as f:
523
+ filename = os.path.basename(f.name)
524
+ filedata = f.read()
525
+ mimetype = (
526
+ mimetypes.guess_type(filename)[0]
527
+ or 'application/octet-stream'
528
+ )
529
+ params.append(
530
+ tuple([k, tuple([filename, filedata, mimetype])])
531
+ )
532
+
533
+ return params
534
+
535
+ def select_header_accept(self, accepts: List[str]) -> Optional[str]:
536
+ """Returns `Accept` based on an array of accepts provided.
537
+
538
+ :param accepts: List of headers.
539
+ :return: Accept (e.g. application/json).
540
+ """
541
+ if not accepts:
542
+ return None
543
+
544
+ for accept in accepts:
545
+ if re.search('json', accept, re.IGNORECASE):
546
+ return accept
547
+
548
+ return accepts[0]
549
+
550
+ def select_header_content_type(self, content_types):
551
+ """Returns `Content-Type` based on an array of content_types provided.
552
+
553
+ :param content_types: List of content-types.
554
+ :return: Content-Type (e.g. application/json).
555
+ """
556
+ if not content_types:
557
+ return None
558
+
559
+ for content_type in content_types:
560
+ if re.search('json', content_type, re.IGNORECASE):
561
+ return content_type
562
+
563
+ return content_types[0]
564
+
565
+ def update_params_for_auth(
566
+ self,
567
+ headers,
568
+ queries,
569
+ auth_settings,
570
+ resource_path,
571
+ method,
572
+ body,
573
+ request_auth=None
574
+ ) -> None:
575
+ """Updates header and query params based on authentication setting.
576
+
577
+ :param headers: Header parameters dict to be updated.
578
+ :param queries: Query parameters tuple list to be updated.
579
+ :param auth_settings: Authentication setting identifiers list.
580
+ :resource_path: A string representation of the HTTP request resource path.
581
+ :method: A string representation of the HTTP request method.
582
+ :body: A object representing the body of the HTTP request.
583
+ The object type is the return value of sanitize_for_serialization().
584
+ :param request_auth: if set, the provided settings will
585
+ override the token in the configuration.
586
+ """
587
+ if not auth_settings:
588
+ return
589
+
590
+ if request_auth:
591
+ self._apply_auth_params(
592
+ headers,
593
+ queries,
594
+ resource_path,
595
+ method,
596
+ body,
597
+ request_auth
598
+ )
599
+ else:
600
+ for auth in auth_settings:
601
+ auth_setting = self.configuration.auth_settings().get(auth)
602
+ if auth_setting:
603
+ self._apply_auth_params(
604
+ headers,
605
+ queries,
606
+ resource_path,
607
+ method,
608
+ body,
609
+ auth_setting
610
+ )
611
+
612
+ def _apply_auth_params(
613
+ self,
614
+ headers,
615
+ queries,
616
+ resource_path,
617
+ method,
618
+ body,
619
+ auth_setting
620
+ ) -> None:
621
+ """Updates the request parameters based on a single auth_setting
622
+
623
+ :param headers: Header parameters dict to be updated.
624
+ :param queries: Query parameters tuple list to be updated.
625
+ :resource_path: A string representation of the HTTP request resource path.
626
+ :method: A string representation of the HTTP request method.
627
+ :body: A object representing the body of the HTTP request.
628
+ The object type is the return value of sanitize_for_serialization().
629
+ :param auth_setting: auth settings for the endpoint
630
+ """
631
+ if auth_setting['in'] == 'cookie':
632
+ headers['Cookie'] = auth_setting['value']
633
+ elif auth_setting['in'] == 'header':
634
+ if auth_setting['type'] != 'http-signature':
635
+ headers[auth_setting['key']] = auth_setting['value']
636
+ elif auth_setting['in'] == 'query':
637
+ queries.append((auth_setting['key'], auth_setting['value']))
638
+ else:
639
+ raise ApiValueError(
640
+ 'Authentication token must be in `query` or `header`'
641
+ )
642
+
643
+ def __deserialize_file(self, response):
644
+ """Deserializes body to file
645
+
646
+ Saves response body into a file in a temporary folder,
647
+ using the filename from the `Content-Disposition` header if provided.
648
+
649
+ handle file downloading
650
+ save response body into a tmp file and return the instance
651
+
652
+ :param response: RESTResponse.
653
+ :return: file path.
654
+ """
655
+ fd, path = tempfile.mkstemp(dir=self.configuration.temp_folder_path)
656
+ os.close(fd)
657
+ os.remove(path)
658
+
659
+ content_disposition = response.getheader("Content-Disposition")
660
+ if content_disposition:
661
+ m = re.search(
662
+ r'filename=[\'"]?([^\'"\s]+)[\'"]?',
663
+ content_disposition
664
+ )
665
+ assert m is not None, "Unexpected 'content-disposition' header value"
666
+ filename = m.group(1)
667
+ path = os.path.join(os.path.dirname(path), filename)
668
+
669
+ with open(path, "wb") as f:
670
+ f.write(response.data)
671
+
672
+ return path
673
+
674
+ def __deserialize_primitive(self, data, klass):
675
+ """Deserializes string to primitive type.
676
+
677
+ :param data: str.
678
+ :param klass: class literal.
679
+
680
+ :return: int, long, float, str, bool.
681
+ """
682
+ try:
683
+ return klass(data)
684
+ except UnicodeEncodeError:
685
+ return str(data)
686
+ except TypeError:
687
+ return data
688
+
689
+ def __deserialize_object(self, value):
690
+ """Return an original value.
691
+
692
+ :return: object.
693
+ """
694
+ return value
695
+
696
+ def __deserialize_date(self, string):
697
+ """Deserializes string to date.
698
+
699
+ :param string: str.
700
+ :return: date.
701
+ """
702
+ try:
703
+ return parse(string).date()
704
+ except ImportError:
705
+ return string
706
+ except ValueError:
707
+ raise rest.ApiException(
708
+ status=0,
709
+ reason="Failed to parse `{0}` as date object".format(string)
710
+ )
711
+
712
+ def __deserialize_datetime(self, string):
713
+ """Deserializes string to datetime.
714
+
715
+ The string should be in iso8601 datetime format.
716
+
717
+ :param string: str.
718
+ :return: datetime.
719
+ """
720
+ try:
721
+ return parse(string)
722
+ except ImportError:
723
+ return string
724
+ except ValueError:
725
+ raise rest.ApiException(
726
+ status=0,
727
+ reason=(
728
+ "Failed to parse `{0}` as datetime object"
729
+ .format(string)
730
+ )
731
+ )
732
+
733
+ def __deserialize_enum(self, data, klass):
734
+ """Deserializes primitive type to enum.
735
+
736
+ :param data: primitive type.
737
+ :param klass: class literal.
738
+ :return: enum value.
739
+ """
740
+ try:
741
+ return klass(data)
742
+ except ValueError:
743
+ raise rest.ApiException(
744
+ status=0,
745
+ reason=(
746
+ "Failed to parse `{0}` as `{1}`"
747
+ .format(data, klass)
748
+ )
749
+ )
750
+
751
+ def __deserialize_model(self, data, klass):
752
+ """Deserializes list or dict to model.
753
+
754
+ :param data: dict, list.
755
+ :param klass: class literal.
756
+ :return: model object.
757
+ """
758
+
759
+ return klass.from_dict(data)