stadiamaps 1.0.6__py3-none-any.whl → 2.0.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.
Files changed (128) hide show
  1. stadiamaps/__init__.py +6 -24
  2. stadiamaps/api/geocoding_api.py +1917 -760
  3. stadiamaps/api/geospatial_api.py +483 -221
  4. stadiamaps/api/routing_api.py +1615 -723
  5. stadiamaps/api_client.py +275 -272
  6. stadiamaps/api_response.py +12 -16
  7. stadiamaps/configuration.py +13 -11
  8. stadiamaps/exceptions.py +67 -30
  9. stadiamaps/models/__init__.py +5 -23
  10. stadiamaps/models/access.py +44 -26
  11. stadiamaps/models/admin_region.py +46 -28
  12. stadiamaps/models/administrative.py +48 -30
  13. stadiamaps/models/auto_costing_options.py +69 -48
  14. stadiamaps/models/auto_costing_options_all_of.py +1 -1
  15. stadiamaps/models/base_costing_options.py +52 -33
  16. stadiamaps/models/base_trace_request.py +70 -40
  17. stadiamaps/models/bicycle_costing_options.py +61 -42
  18. stadiamaps/models/bicycle_costing_options_all_of.py +1 -1
  19. stadiamaps/models/bike_network.py +42 -24
  20. stadiamaps/models/contour.py +45 -27
  21. stadiamaps/models/coordinate.py +45 -26
  22. stadiamaps/models/costing_model.py +10 -12
  23. stadiamaps/models/costing_options.py +51 -33
  24. stadiamaps/models/directions_options.py +45 -27
  25. stadiamaps/models/distance_unit.py +8 -11
  26. stadiamaps/models/edge_sign.py +46 -28
  27. stadiamaps/models/edge_use.py +8 -11
  28. stadiamaps/models/end_node.py +48 -30
  29. stadiamaps/models/geo_attributes.py +47 -29
  30. stadiamaps/models/geo_json_geometry.py +25 -25
  31. stadiamaps/models/geo_json_geometry_base.py +45 -27
  32. stadiamaps/models/geo_json_line_string.py +47 -28
  33. stadiamaps/models/geo_json_line_string_all_of.py +2 -2
  34. stadiamaps/models/geo_json_point.py +47 -28
  35. stadiamaps/models/geo_json_point_all_of.py +2 -2
  36. stadiamaps/models/geo_json_polygon.py +47 -28
  37. stadiamaps/models/geo_json_polygon_all_of.py +2 -2
  38. stadiamaps/models/geocoding_object.py +46 -28
  39. stadiamaps/models/height_request.py +55 -34
  40. stadiamaps/models/height_response.py +49 -30
  41. stadiamaps/models/highway_classification.py +52 -34
  42. stadiamaps/models/intersecting_edge.py +45 -27
  43. stadiamaps/models/isochrone_costing_model.py +8 -11
  44. stadiamaps/models/isochrone_feature.py +45 -27
  45. stadiamaps/models/isochrone_properties.py +48 -30
  46. stadiamaps/models/isochrone_request.py +54 -35
  47. stadiamaps/models/isochrone_response.py +47 -29
  48. stadiamaps/models/locate_detailed_edge.py +73 -55
  49. stadiamaps/models/locate_edge.py +56 -39
  50. stadiamaps/models/locate_edge_info.py +47 -29
  51. stadiamaps/models/locate_node.py +50 -31
  52. stadiamaps/models/locate_node_all_of.py +1 -1
  53. stadiamaps/models/locate_object.py +49 -31
  54. stadiamaps/models/maneuver_sign.py +50 -32
  55. stadiamaps/models/maneuver_sign_element.py +45 -27
  56. stadiamaps/models/map_match_costing_model.py +8 -11
  57. stadiamaps/models/map_match_request.py +74 -44
  58. stadiamaps/models/map_match_request_all_of.py +1 -1
  59. stadiamaps/models/map_match_route_response.py +57 -29
  60. stadiamaps/models/map_match_route_response_all_of.py +1 -1
  61. stadiamaps/models/map_match_trace_options.py +47 -29
  62. stadiamaps/models/map_match_waypoint.py +49 -30
  63. stadiamaps/models/map_match_waypoint_all_of.py +1 -1
  64. stadiamaps/models/matched_point.py +52 -34
  65. stadiamaps/models/matrix_costing_model.py +9 -12
  66. stadiamaps/models/matrix_distance.py +46 -28
  67. stadiamaps/models/matrix_request.py +70 -39
  68. stadiamaps/models/matrix_response.py +60 -36
  69. stadiamaps/models/motor_scooter_costing_options.py +70 -49
  70. stadiamaps/models/motor_scooter_costing_options_all_of.py +1 -1
  71. stadiamaps/models/motorcycle_costing_options.py +69 -48
  72. stadiamaps/models/motorcycle_costing_options_all_of.py +1 -1
  73. stadiamaps/models/nearest_roads_request.py +65 -34
  74. stadiamaps/models/node_id.py +42 -24
  75. stadiamaps/models/node_type.py +8 -11
  76. stadiamaps/models/optimized_route_request.py +66 -35
  77. stadiamaps/models/pedestrian_costing_options.py +59 -40
  78. stadiamaps/models/pelias_geo_json_feature.py +50 -31
  79. stadiamaps/models/pelias_geo_json_properties.py +54 -36
  80. stadiamaps/models/pelias_geo_json_properties_addendum.py +43 -25
  81. stadiamaps/models/pelias_geo_json_properties_addendum_osm.py +42 -24
  82. stadiamaps/models/pelias_layer.py +8 -11
  83. stadiamaps/models/pelias_response.py +49 -30
  84. stadiamaps/models/pelias_response_geocoding.py +1 -1
  85. stadiamaps/models/pelias_source.py +8 -11
  86. stadiamaps/models/restrictions.py +44 -26
  87. stadiamaps/models/road_class.py +8 -11
  88. stadiamaps/models/route_leg.py +48 -29
  89. stadiamaps/models/route_maneuver.py +73 -55
  90. stadiamaps/models/route_request.py +76 -43
  91. stadiamaps/models/route_response.py +56 -28
  92. stadiamaps/models/route_response_alternates_inner.py +105 -0
  93. stadiamaps/models/route_response_trip.py +1 -1
  94. stadiamaps/models/route_summary.py +48 -30
  95. stadiamaps/models/route_trip.py +135 -0
  96. stadiamaps/models/routing_response_waypoint.py +49 -30
  97. stadiamaps/models/routing_response_waypoint_all_of.py +1 -1
  98. stadiamaps/models/routing_waypoint.py +60 -41
  99. stadiamaps/models/routing_waypoint_all_of.py +1 -1
  100. stadiamaps/models/routing_waypoint_all_of_search_filter.py +48 -30
  101. stadiamaps/models/simple_routing_waypoint.py +48 -29
  102. stadiamaps/models/simple_routing_waypoint_all_of.py +1 -1
  103. stadiamaps/models/speeds.py +49 -31
  104. stadiamaps/models/trace_attribute_filter_options.py +47 -28
  105. stadiamaps/models/trace_attribute_key.py +8 -11
  106. stadiamaps/models/trace_attributes_base_response.py +51 -32
  107. stadiamaps/models/trace_attributes_request.py +72 -42
  108. stadiamaps/models/trace_attributes_request_all_of.py +1 -1
  109. stadiamaps/models/trace_attributes_request_all_of_filters.py +2 -2
  110. stadiamaps/models/trace_attributes_response.py +54 -35
  111. stadiamaps/models/trace_attributes_response_all_of.py +1 -1
  112. stadiamaps/models/trace_edge.py +88 -70
  113. stadiamaps/models/travel_mode.py +8 -11
  114. stadiamaps/models/traversability.py +8 -11
  115. stadiamaps/models/truck_costing_options.py +72 -51
  116. stadiamaps/models/truck_costing_options_all_of.py +1 -1
  117. stadiamaps/models/tz_response.py +45 -27
  118. stadiamaps/models/valhalla_languages.py +8 -11
  119. stadiamaps/models/valhalla_long_units.py +8 -11
  120. stadiamaps/models/warning.py +42 -24
  121. stadiamaps/py.typed +0 -0
  122. stadiamaps/rest.py +127 -172
  123. {stadiamaps-1.0.6.dist-info → stadiamaps-2.0.0.dist-info}/METADATA +4 -4
  124. stadiamaps-2.0.0.dist-info/RECORD +128 -0
  125. {stadiamaps-1.0.6.dist-info → stadiamaps-2.0.0.dist-info}/WHEEL +1 -1
  126. stadiamaps-1.0.6.dist-info/RECORD +0 -125
  127. {stadiamaps-1.0.6.dist-info → stadiamaps-2.0.0.dist-info}/LICENSE.txt +0 -0
  128. {stadiamaps-1.0.6.dist-info → stadiamaps-2.0.0.dist-info}/top_level.txt +0 -0
stadiamaps/api_client.py CHANGED
@@ -3,36 +3,45 @@
3
3
  """
4
4
  Stadia Maps Geospatial APIs
5
5
 
6
- The Stadia Maps Geospatial APIs provide you with the data you need to build awesome applications. # noqa: E501
6
+ The Stadia Maps Geospatial APIs provide you with the data you need to build awesome applications.
7
7
 
8
- The version of the OpenAPI document: 5.0.5
8
+ The version of the OpenAPI document: 6.0.0
9
9
  Contact: support@stadiamaps.com
10
10
  Generated by OpenAPI Generator (https://openapi-generator.tech)
11
11
 
12
12
  Do not edit the class manually.
13
- """
13
+ """ # noqa: E501
14
14
 
15
15
 
16
- import atexit
17
16
  import datetime
18
17
  from dateutil.parser import parse
18
+ from enum import Enum
19
19
  import json
20
20
  import mimetypes
21
- from multiprocessing.pool import ThreadPool
22
21
  import os
23
22
  import re
24
23
  import tempfile
25
24
 
26
25
  from urllib.parse import quote
26
+ from typing import Tuple, Optional, List, Dict
27
27
 
28
28
  from stadiamaps.configuration import Configuration
29
- from stadiamaps.api_response import ApiResponse
29
+ from stadiamaps.api_response import ApiResponse, T as ApiResponseT
30
30
  import stadiamaps.models
31
31
  from stadiamaps import rest
32
- from stadiamaps.exceptions import ApiValueError, ApiException
33
-
34
-
35
- class ApiClient(object):
32
+ from stadiamaps.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:
36
45
  """Generic API client for OpenAPI client library builds.
37
46
 
38
47
  OpenAPI generic API client. This client handles the client-
@@ -46,8 +55,6 @@ class ApiClient(object):
46
55
  the API.
47
56
  :param cookie: a cookie to include in the header when making calls
48
57
  to the API
49
- :param pool_threads: The number of threads to use for async requests
50
- to the API. More threads means more concurrent API requests.
51
58
  """
52
59
 
53
60
  PRIMITIVE_TYPES = (float, bool, bytes, str, int)
@@ -63,13 +70,17 @@ class ApiClient(object):
63
70
  }
64
71
  _pool = None
65
72
 
66
- def __init__(self, configuration=None, header_name=None, header_value=None,
67
- cookie=None, pool_threads=1):
73
+ def __init__(
74
+ self,
75
+ configuration=None,
76
+ header_name=None,
77
+ header_value=None,
78
+ cookie=None
79
+ ) -> None:
68
80
  # use default configuration if none is provided
69
81
  if configuration is None:
70
82
  configuration = Configuration.get_default()
71
83
  self.configuration = configuration
72
- self.pool_threads = pool_threads
73
84
 
74
85
  self.rest_client = rest.RESTClientObject(configuration)
75
86
  self.default_headers = {}
@@ -77,32 +88,14 @@ class ApiClient(object):
77
88
  self.default_headers[header_name] = header_value
78
89
  self.cookie = cookie
79
90
  # Set default User-Agent.
80
- self.user_agent = 'stadiamaps/1.0.6/python'
91
+ self.user_agent = 'OpenAPI-Generator/2.0.0/python'
81
92
  self.client_side_validation = configuration.client_side_validation
82
93
 
83
94
  def __enter__(self):
84
95
  return self
85
96
 
86
97
  def __exit__(self, exc_type, exc_value, traceback):
87
- self.close()
88
-
89
- def close(self):
90
- if self._pool:
91
- self._pool.close()
92
- self._pool.join()
93
- self._pool = None
94
- if hasattr(atexit, 'unregister'):
95
- atexit.unregister(self.close)
96
-
97
- @property
98
- def pool(self):
99
- """Create thread pool on first request
100
- avoids instantiating unused threadpool for blocking clients.
101
- """
102
- if self._pool is None:
103
- atexit.register(self.close)
104
- self._pool = ThreadPool(self.pool_threads)
105
- return self._pool
98
+ pass
106
99
 
107
100
  @property
108
101
  def user_agent(self):
@@ -143,13 +136,42 @@ class ApiClient(object):
143
136
  """
144
137
  cls._default = default
145
138
 
146
- def __call_api(
147
- self, resource_path, method, path_params=None,
148
- query_params=None, header_params=None, body=None, post_params=None,
149
- files=None, response_types_map=None, auth_settings=None,
150
- _return_http_data_only=None, collection_formats=None,
151
- _preload_content=True, _request_timeout=None, _host=None,
152
- _request_auth=None):
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
+ """
153
175
 
154
176
  config = self.configuration
155
177
 
@@ -160,14 +182,17 @@ class ApiClient(object):
160
182
  header_params['Cookie'] = self.cookie
161
183
  if header_params:
162
184
  header_params = self.sanitize_for_serialization(header_params)
163
- header_params = dict(self.parameters_to_tuples(header_params,
164
- collection_formats))
185
+ header_params = dict(
186
+ self.parameters_to_tuples(header_params,collection_formats)
187
+ )
165
188
 
166
189
  # path parameters
167
190
  if path_params:
168
191
  path_params = self.sanitize_for_serialization(path_params)
169
- path_params = self.parameters_to_tuples(path_params,
170
- collection_formats)
192
+ path_params = self.parameters_to_tuples(
193
+ path_params,
194
+ collection_formats
195
+ )
171
196
  for k, v in path_params:
172
197
  # specified safe chars, encode everything
173
198
  resource_path = resource_path.replace(
@@ -179,15 +204,22 @@ class ApiClient(object):
179
204
  if post_params or files:
180
205
  post_params = post_params if post_params else []
181
206
  post_params = self.sanitize_for_serialization(post_params)
182
- post_params = self.parameters_to_tuples(post_params,
183
- collection_formats)
207
+ post_params = self.parameters_to_tuples(
208
+ post_params,
209
+ collection_formats
210
+ )
184
211
  post_params.extend(self.files_parameters(files))
185
212
 
186
213
  # auth setting
187
214
  self.update_params_for_auth(
188
- header_params, query_params, auth_settings,
189
- resource_path, method, body,
190
- request_auth=_request_auth)
215
+ header_params,
216
+ query_params,
217
+ auth_settings,
218
+ resource_path,
219
+ method,
220
+ body,
221
+ request_auth=_request_auth
222
+ )
191
223
 
192
224
  # body
193
225
  if body:
@@ -203,56 +235,99 @@ class ApiClient(object):
203
235
  # query parameters
204
236
  if query_params:
205
237
  query_params = self.sanitize_for_serialization(query_params)
206
- url_query = self.parameters_to_url_query(query_params,
207
- collection_formats)
238
+ url_query = self.parameters_to_url_query(
239
+ query_params,
240
+ collection_formats
241
+ )
208
242
  url += "?" + url_query
209
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
+
210
268
  try:
211
269
  # perform request and return response
212
- response_data = self.request(
270
+ response_data = self.rest_client.request(
213
271
  method, url,
214
- query_params=query_params,
215
272
  headers=header_params,
216
- post_params=post_params, body=body,
217
- _preload_content=_preload_content,
218
- _request_timeout=_request_timeout)
273
+ body=body, post_params=post_params,
274
+ _request_timeout=_request_timeout
275
+ )
276
+
219
277
  except ApiException as e:
220
- if e.body:
221
- e.body = e.body.decode('utf-8')
222
278
  raise e
223
279
 
224
- self.last_response = response_data
225
-
226
- return_data = None # assuming derialization is not needed
227
- # data needs deserialization or returns HTTP data (deserialized) only
228
- if _preload_content or _return_http_data_only:
229
- response_type = response_types_map.get(str(response_data.status), None)
230
-
231
- if response_type == "bytearray":
232
- response_data.data = response_data.data
233
- else:
234
- match = None
235
- content_type = response_data.getheader('content-type')
236
- if content_type is not None:
237
- match = re.search(r"charset=([a-zA-Z\-\d]+)[\s;]?", content_type)
238
- encoding = match.group(1) if match else "utf-8"
239
- response_data.data = response_data.data.decode(encoding)
240
-
241
- # deserialize response data
242
- if response_type == "bytearray":
243
- return_data = response_data.data
244
- elif response_type:
245
- return_data = self.deserialize(response_data, response_type)
246
- else:
247
- return_data = None
248
-
249
- if _return_http_data_only:
250
- return return_data
251
- else:
252
- return ApiResponse(status_code = response_data.status,
253
- data = return_data,
254
- headers = response_data.getheaders(),
255
- raw_data = response_data.data)
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
+ )
256
331
 
257
332
  def sanitize_for_serialization(self, obj):
258
333
  """Builds a JSON POST object.
@@ -273,15 +348,17 @@ class ApiClient(object):
273
348
  elif isinstance(obj, self.PRIMITIVE_TYPES):
274
349
  return obj
275
350
  elif isinstance(obj, list):
276
- return [self.sanitize_for_serialization(sub_obj)
277
- for sub_obj in obj]
351
+ return [
352
+ self.sanitize_for_serialization(sub_obj) for sub_obj in obj
353
+ ]
278
354
  elif isinstance(obj, tuple):
279
- return tuple(self.sanitize_for_serialization(sub_obj)
280
- for sub_obj in obj)
355
+ return tuple(
356
+ self.sanitize_for_serialization(sub_obj) for sub_obj in obj
357
+ )
281
358
  elif isinstance(obj, (datetime.datetime, datetime.date)):
282
359
  return obj.isoformat()
283
360
 
284
- if isinstance(obj, dict):
361
+ elif isinstance(obj, dict):
285
362
  obj_dict = obj
286
363
  else:
287
364
  # Convert model obj to dict except
@@ -291,10 +368,12 @@ class ApiClient(object):
291
368
  # model definition for request.
292
369
  obj_dict = obj.to_dict()
293
370
 
294
- return {key: self.sanitize_for_serialization(val)
295
- for key, val in obj_dict.items()}
371
+ return {
372
+ key: self.sanitize_for_serialization(val)
373
+ for key, val in obj_dict.items()
374
+ }
296
375
 
297
- def deserialize(self, response, response_type):
376
+ def deserialize(self, response_text, response_type):
298
377
  """Deserializes response into an object.
299
378
 
300
379
  :param response: RESTResponse object to be deserialized.
@@ -303,16 +382,12 @@ class ApiClient(object):
303
382
 
304
383
  :return: deserialized object.
305
384
  """
306
- # handle file downloading
307
- # save response body into a tmp file and return the instance
308
- if response_type == "file":
309
- return self.__deserialize_file(response)
310
385
 
311
386
  # fetch data from response object
312
387
  try:
313
- data = json.loads(response.data)
388
+ data = json.loads(response_text)
314
389
  except ValueError:
315
- data = response.data
390
+ data = response_text
316
391
 
317
392
  return self.__deserialize(data, response_type)
318
393
 
@@ -327,14 +402,18 @@ class ApiClient(object):
327
402
  if data is None:
328
403
  return None
329
404
 
330
- if type(klass) == str:
405
+ if isinstance(klass, str):
331
406
  if klass.startswith('List['):
332
- sub_kls = re.match(r'List\[(.*)]', klass).group(1)
407
+ m = re.match(r'List\[(.*)]', klass)
408
+ assert m is not None, "Malformed List type definition"
409
+ sub_kls = m.group(1)
333
410
  return [self.__deserialize(sub_data, sub_kls)
334
411
  for sub_data in data]
335
412
 
336
413
  if klass.startswith('Dict['):
337
- sub_kls = re.match(r'Dict\[([^,]*), (.*)]', klass).group(2)
414
+ m = re.match(r'Dict\[([^,]*), (.*)]', klass)
415
+ assert m is not None, "Malformed Dict type definition"
416
+ sub_kls = m.group(2)
338
417
  return {k: self.__deserialize(v, sub_kls)
339
418
  for k, v in data.items()}
340
419
 
@@ -352,138 +431,11 @@ class ApiClient(object):
352
431
  return self.__deserialize_date(data)
353
432
  elif klass == datetime.datetime:
354
433
  return self.__deserialize_datetime(data)
434
+ elif issubclass(klass, Enum):
435
+ return self.__deserialize_enum(data, klass)
355
436
  else:
356
437
  return self.__deserialize_model(data, klass)
357
438
 
358
- def call_api(self, resource_path, method,
359
- path_params=None, query_params=None, header_params=None,
360
- body=None, post_params=None, files=None,
361
- response_types_map=None, auth_settings=None,
362
- async_req=None, _return_http_data_only=None,
363
- collection_formats=None, _preload_content=True,
364
- _request_timeout=None, _host=None, _request_auth=None):
365
- """Makes the HTTP request (synchronous) and returns deserialized data.
366
-
367
- To make an async_req request, set the async_req parameter.
368
-
369
- :param resource_path: Path to method endpoint.
370
- :param method: Method to call.
371
- :param path_params: Path parameters in the url.
372
- :param query_params: Query parameters in the url.
373
- :param header_params: Header parameters to be
374
- placed in the request header.
375
- :param body: Request body.
376
- :param post_params dict: Request post form parameters,
377
- for `application/x-www-form-urlencoded`, `multipart/form-data`.
378
- :param auth_settings list: Auth Settings names for the request.
379
- :param response: Response data type.
380
- :param files dict: key -> filename, value -> filepath,
381
- for `multipart/form-data`.
382
- :param async_req bool: execute request asynchronously
383
- :param _return_http_data_only: response data instead of ApiResponse
384
- object with status code, headers, etc
385
- :param _preload_content: if False, the ApiResponse.data will
386
- be set to none and raw_data will store the
387
- HTTP response body without reading/decoding.
388
- Default is True.
389
- :param collection_formats: dict of collection formats for path, query,
390
- header, and post parameters.
391
- :param _request_timeout: timeout setting for this request. If one
392
- number provided, it will be total request
393
- timeout. It can also be a pair (tuple) of
394
- (connection, read) timeouts.
395
- :param _request_auth: set to override the auth_settings for an a single
396
- request; this effectively ignores the authentication
397
- in the spec for a single request.
398
- :type _request_token: dict, optional
399
- :return:
400
- If async_req parameter is True,
401
- the request will be called asynchronously.
402
- The method will return the request thread.
403
- If parameter async_req is False or missing,
404
- then the method will return the response directly.
405
- """
406
- if not async_req:
407
- return self.__call_api(resource_path, method,
408
- path_params, query_params, header_params,
409
- body, post_params, files,
410
- response_types_map, auth_settings,
411
- _return_http_data_only, collection_formats,
412
- _preload_content, _request_timeout, _host,
413
- _request_auth)
414
-
415
- return self.pool.apply_async(self.__call_api, (resource_path,
416
- method, path_params,
417
- query_params,
418
- header_params, body,
419
- post_params, files,
420
- response_types_map,
421
- auth_settings,
422
- _return_http_data_only,
423
- collection_formats,
424
- _preload_content,
425
- _request_timeout,
426
- _host, _request_auth))
427
-
428
- def request(self, method, url, query_params=None, headers=None,
429
- post_params=None, body=None, _preload_content=True,
430
- _request_timeout=None):
431
- """Makes the HTTP request using RESTClient."""
432
- if method == "GET":
433
- return self.rest_client.get_request(url,
434
- query_params=query_params,
435
- _preload_content=_preload_content,
436
- _request_timeout=_request_timeout,
437
- headers=headers)
438
- elif method == "HEAD":
439
- return self.rest_client.head_request(url,
440
- query_params=query_params,
441
- _preload_content=_preload_content,
442
- _request_timeout=_request_timeout,
443
- headers=headers)
444
- elif method == "OPTIONS":
445
- return self.rest_client.options_request(url,
446
- query_params=query_params,
447
- headers=headers,
448
- _preload_content=_preload_content,
449
- _request_timeout=_request_timeout)
450
- elif method == "POST":
451
- return self.rest_client.post_request(url,
452
- query_params=query_params,
453
- headers=headers,
454
- post_params=post_params,
455
- _preload_content=_preload_content,
456
- _request_timeout=_request_timeout,
457
- body=body)
458
- elif method == "PUT":
459
- return self.rest_client.put_request(url,
460
- query_params=query_params,
461
- headers=headers,
462
- post_params=post_params,
463
- _preload_content=_preload_content,
464
- _request_timeout=_request_timeout,
465
- body=body)
466
- elif method == "PATCH":
467
- return self.rest_client.patch_request(url,
468
- query_params=query_params,
469
- headers=headers,
470
- post_params=post_params,
471
- _preload_content=_preload_content,
472
- _request_timeout=_request_timeout,
473
- body=body)
474
- elif method == "DELETE":
475
- return self.rest_client.delete_request(url,
476
- query_params=query_params,
477
- headers=headers,
478
- _preload_content=_preload_content,
479
- _request_timeout=_request_timeout,
480
- body=body)
481
- else:
482
- raise ApiValueError(
483
- "http method must be `GET`, `HEAD`, `OPTIONS`,"
484
- " `POST`, `PATCH`, `PUT` or `DELETE`."
485
- )
486
-
487
439
  def parameters_to_tuples(self, params, collection_formats):
488
440
  """Get parameters as list of tuples, formatting collections.
489
441
 
@@ -491,10 +443,10 @@ class ApiClient(object):
491
443
  :param dict collection_formats: Parameter collection formats
492
444
  :return: Parameters as list of tuples, collections formatted
493
445
  """
494
- new_params = []
446
+ new_params: List[Tuple[str, str]] = []
495
447
  if collection_formats is None:
496
448
  collection_formats = {}
497
- for k, v in params.items() if isinstance(params, dict) else params: # noqa: E501
449
+ for k, v in params.items() if isinstance(params, dict) else params:
498
450
  if k in collection_formats:
499
451
  collection_format = collection_formats[k]
500
452
  if collection_format == 'multi':
@@ -521,21 +473,21 @@ class ApiClient(object):
521
473
  :param dict collection_formats: Parameter collection formats
522
474
  :return: URL query string (e.g. a=Hello%20World&b=123)
523
475
  """
524
- new_params = []
476
+ new_params: List[Tuple[str, str]] = []
525
477
  if collection_formats is None:
526
478
  collection_formats = {}
527
- for k, v in params.items() if isinstance(params, dict) else params: # noqa: E501
528
- if isinstance(v, (int, float)):
529
- v = str(v)
479
+ for k, v in params.items() if isinstance(params, dict) else params:
530
480
  if isinstance(v, bool):
531
481
  v = str(v).lower()
482
+ if isinstance(v, (int, float)):
483
+ v = str(v)
532
484
  if isinstance(v, dict):
533
485
  v = json.dumps(v)
534
486
 
535
487
  if k in collection_formats:
536
488
  collection_format = collection_formats[k]
537
489
  if collection_format == 'multi':
538
- new_params.extend((k, value) for value in v)
490
+ new_params.extend((k, str(value)) for value in v)
539
491
  else:
540
492
  if collection_format == 'ssv':
541
493
  delimiter = ' '
@@ -546,11 +498,12 @@ class ApiClient(object):
546
498
  else: # csv is the default
547
499
  delimiter = ','
548
500
  new_params.append(
549
- (k, delimiter.join(quote(str(value)) for value in v)))
501
+ (k, delimiter.join(quote(str(value)) for value in v))
502
+ )
550
503
  else:
551
504
  new_params.append((k, quote(str(v))))
552
505
 
553
- return "&".join(["=".join(item) for item in new_params])
506
+ return "&".join(["=".join(map(str, item)) for item in new_params])
554
507
 
555
508
  def files_parameters(self, files=None):
556
509
  """Builds form parameters.
@@ -569,21 +522,24 @@ class ApiClient(object):
569
522
  with open(n, 'rb') as f:
570
523
  filename = os.path.basename(f.name)
571
524
  filedata = f.read()
572
- mimetype = (mimetypes.guess_type(filename)[0] or
573
- 'application/octet-stream')
525
+ mimetype = (
526
+ mimetypes.guess_type(filename)[0]
527
+ or 'application/octet-stream'
528
+ )
574
529
  params.append(
575
- tuple([k, tuple([filename, filedata, mimetype])]))
530
+ tuple([k, tuple([filename, filedata, mimetype])])
531
+ )
576
532
 
577
533
  return params
578
534
 
579
- def select_header_accept(self, accepts):
535
+ def select_header_accept(self, accepts: List[str]) -> Optional[str]:
580
536
  """Returns `Accept` based on an array of accepts provided.
581
537
 
582
538
  :param accepts: List of headers.
583
539
  :return: Accept (e.g. application/json).
584
540
  """
585
541
  if not accepts:
586
- return
542
+ return None
587
543
 
588
544
  for accept in accepts:
589
545
  if re.search('json', accept, re.IGNORECASE):
@@ -606,9 +562,16 @@ class ApiClient(object):
606
562
 
607
563
  return content_types[0]
608
564
 
609
- def update_params_for_auth(self, headers, queries, auth_settings,
610
- resource_path, method, body,
611
- request_auth=None):
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:
612
575
  """Updates header and query params based on authentication setting.
613
576
 
614
577
  :param headers: Header parameters dict to be updated.
@@ -625,21 +588,36 @@ class ApiClient(object):
625
588
  return
626
589
 
627
590
  if request_auth:
628
- self._apply_auth_params(headers, queries,
629
- resource_path, method, body,
630
- request_auth)
631
- return
632
-
633
- for auth in auth_settings:
634
- auth_setting = self.configuration.auth_settings().get(auth)
635
- if auth_setting:
636
- self._apply_auth_params(headers, queries,
637
- resource_path, method, body,
638
- auth_setting)
639
-
640
- def _apply_auth_params(self, headers, queries,
641
- resource_path, method, body,
642
- auth_setting):
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:
643
621
  """Updates the request parameters based on a single auth_setting
644
622
 
645
623
  :param headers: Header parameters dict to be updated.
@@ -668,6 +646,9 @@ class ApiClient(object):
668
646
  Saves response body into a file in a temporary folder,
669
647
  using the filename from the `Content-Disposition` header if provided.
670
648
 
649
+ handle file downloading
650
+ save response body into a tmp file and return the instance
651
+
671
652
  :param response: RESTResponse.
672
653
  :return: file path.
673
654
  """
@@ -677,8 +658,12 @@ class ApiClient(object):
677
658
 
678
659
  content_disposition = response.getheader("Content-Disposition")
679
660
  if content_disposition:
680
- filename = re.search(r'filename=[\'"]?([^\'"\s]+)[\'"]?',
681
- content_disposition).group(1)
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)
682
667
  path = os.path.join(os.path.dirname(path), filename)
683
668
 
684
669
  with open(path, "wb") as f:
@@ -745,6 +730,24 @@ class ApiClient(object):
745
730
  )
746
731
  )
747
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
+
748
751
  def __deserialize_model(self, data, klass):
749
752
  """Deserializes list or dict to model.
750
753