cbbd 1.1.0a1__py3-none-any.whl

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. cbbd/__init__.py +64 -0
  2. cbbd/api/__init__.py +10 -0
  3. cbbd/api/conferences_api.py +176 -0
  4. cbbd/api/games_api.py +806 -0
  5. cbbd/api/plays_api.py +761 -0
  6. cbbd/api/stats_api.py +423 -0
  7. cbbd/api/teams_api.py +195 -0
  8. cbbd/api/venues_api.py +176 -0
  9. cbbd/api_client.py +767 -0
  10. cbbd/api_response.py +25 -0
  11. cbbd/configuration.py +443 -0
  12. cbbd/exceptions.py +167 -0
  13. cbbd/models/__init__.py +42 -0
  14. cbbd/models/conference_info.py +80 -0
  15. cbbd/models/game_box_score_players.py +147 -0
  16. cbbd/models/game_box_score_players_players_inner.py +238 -0
  17. cbbd/models/game_box_score_team.py +148 -0
  18. cbbd/models/game_box_score_team_stats.py +170 -0
  19. cbbd/models/game_box_score_team_stats_points.py +112 -0
  20. cbbd/models/game_info.py +212 -0
  21. cbbd/models/game_media_info.py +133 -0
  22. cbbd/models/game_media_info_broadcasts_inner.py +74 -0
  23. cbbd/models/game_status.py +44 -0
  24. cbbd/models/play_info.py +193 -0
  25. cbbd/models/play_info_participants_inner.py +74 -0
  26. cbbd/models/play_type_info.py +74 -0
  27. cbbd/models/player_season_stats.py +231 -0
  28. cbbd/models/season_type.py +42 -0
  29. cbbd/models/team_info.py +160 -0
  30. cbbd/models/team_season_stats.py +112 -0
  31. cbbd/models/team_season_unit_stats.py +163 -0
  32. cbbd/models/team_season_unit_stats_field_goals.py +91 -0
  33. cbbd/models/team_season_unit_stats_fouls.py +91 -0
  34. cbbd/models/team_season_unit_stats_four_factors.py +98 -0
  35. cbbd/models/team_season_unit_stats_points.py +98 -0
  36. cbbd/models/team_season_unit_stats_rebounds.py +91 -0
  37. cbbd/models/team_season_unit_stats_turnovers.py +84 -0
  38. cbbd/models/venue_info.py +102 -0
  39. cbbd/py.typed +0 -0
  40. cbbd/rest.py +330 -0
  41. cbbd-1.1.0a1.dist-info/METADATA +24 -0
  42. cbbd-1.1.0a1.dist-info/RECORD +44 -0
  43. cbbd-1.1.0a1.dist-info/WHEEL +5 -0
  44. cbbd-1.1.0a1.dist-info/top_level.txt +1 -0
cbbd/api_client.py ADDED
@@ -0,0 +1,767 @@
1
+ # coding: utf-8
2
+
3
+ """
4
+ College Basketball Data API
5
+
6
+ This API is in limited Beta for Patreon subscribers. It may have bugs and is subject to changes. API keys can be acquired from the CollegeFootballData.com website.
7
+
8
+ The version of the OpenAPI document: 1.1.0
9
+ Contact: admin@collegefootballdata.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 atexit
17
+ import datetime
18
+ from dateutil.parser import parse
19
+ import json
20
+ import mimetypes
21
+ from multiprocessing.pool import ThreadPool
22
+ import os
23
+ import re
24
+ import tempfile
25
+
26
+ from urllib.parse import quote
27
+ from pydantic import SecretStr
28
+
29
+ from cbbd.configuration import Configuration
30
+ from cbbd.api_response import ApiResponse
31
+ import cbbd.models
32
+ from cbbd import rest
33
+ from cbbd.exceptions import ApiValueError, ApiException
34
+
35
+
36
+ class ApiClient:
37
+ """Generic API client for OpenAPI client library builds.
38
+
39
+ OpenAPI generic API client. This client handles the client-
40
+ server communication, and is invariant across implementations. Specifics of
41
+ the methods and models for each application are generated from the OpenAPI
42
+ templates.
43
+
44
+ :param configuration: .Configuration object for this client
45
+ :param header_name: a header to pass when making calls to the API.
46
+ :param header_value: a header value to pass when making calls to
47
+ the API.
48
+ :param cookie: a cookie to include in the header when making calls
49
+ to the API
50
+ :param pool_threads: The number of threads to use for async requests
51
+ to the API. More threads means more concurrent API requests.
52
+ """
53
+
54
+ PRIMITIVE_TYPES = (float, bool, bytes, str, int)
55
+ NATIVE_TYPES_MAPPING = {
56
+ 'int': int,
57
+ 'long': int, # TODO remove as only py3 is supported?
58
+ 'float': float,
59
+ 'str': str,
60
+ 'bool': bool,
61
+ 'date': datetime.date,
62
+ 'datetime': datetime.datetime,
63
+ 'object': object,
64
+ }
65
+ _pool = None
66
+
67
+ def __init__(self, configuration=None, header_name=None, header_value=None,
68
+ cookie=None, pool_threads=1) -> None:
69
+ # use default configuration if none is provided
70
+ if configuration is None:
71
+ configuration = Configuration.get_default()
72
+ self.configuration = configuration
73
+ self.pool_threads = pool_threads
74
+
75
+ self.rest_client = rest.RESTClientObject(configuration)
76
+ self.default_headers = {}
77
+ if header_name is not None:
78
+ self.default_headers[header_name] = header_value
79
+ self.cookie = cookie
80
+ # Set default User-Agent.
81
+ self.user_agent = 'OpenAPI-Generator/1.1.0a1/python'
82
+ self.client_side_validation = configuration.client_side_validation
83
+
84
+ def __enter__(self):
85
+ return self
86
+
87
+ def __exit__(self, exc_type, exc_value, traceback):
88
+ self.close()
89
+
90
+ def close(self):
91
+ if self._pool:
92
+ self._pool.close()
93
+ self._pool.join()
94
+ self._pool = None
95
+ if hasattr(atexit, 'unregister'):
96
+ atexit.unregister(self.close)
97
+
98
+ @property
99
+ def pool(self):
100
+ """Create thread pool on first request
101
+ avoids instantiating unused threadpool for blocking clients.
102
+ """
103
+ if self._pool is None:
104
+ atexit.register(self.close)
105
+ self._pool = ThreadPool(self.pool_threads)
106
+ return self._pool
107
+
108
+ @property
109
+ def user_agent(self):
110
+ """User agent for this API client"""
111
+ return self.default_headers['User-Agent']
112
+
113
+ @user_agent.setter
114
+ def user_agent(self, value):
115
+ self.default_headers['User-Agent'] = value
116
+
117
+ def set_default_header(self, header_name, header_value):
118
+ self.default_headers[header_name] = header_value
119
+
120
+
121
+ _default = None
122
+
123
+ @classmethod
124
+ def get_default(cls):
125
+ """Return new instance of ApiClient.
126
+
127
+ This method returns newly created, based on default constructor,
128
+ object of ApiClient class or returns a copy of default
129
+ ApiClient.
130
+
131
+ :return: The ApiClient object.
132
+ """
133
+ if cls._default is None:
134
+ cls._default = ApiClient()
135
+ return cls._default
136
+
137
+ @classmethod
138
+ def set_default(cls, default):
139
+ """Set default instance of ApiClient.
140
+
141
+ It stores default ApiClient.
142
+
143
+ :param default: object of ApiClient.
144
+ """
145
+ cls._default = default
146
+
147
+ def __call_api(
148
+ self, resource_path, method, path_params=None,
149
+ query_params=None, header_params=None, body=None, post_params=None,
150
+ files=None, response_types_map=None, auth_settings=None,
151
+ _return_http_data_only=None, collection_formats=None,
152
+ _preload_content=True, _request_timeout=None, _host=None,
153
+ _request_auth=None):
154
+
155
+ config = self.configuration
156
+
157
+ # header parameters
158
+ header_params = header_params or {}
159
+ header_params.update(self.default_headers)
160
+ if self.cookie:
161
+ header_params['Cookie'] = self.cookie
162
+ if header_params:
163
+ header_params = self.sanitize_for_serialization(header_params)
164
+ header_params = dict(self.parameters_to_tuples(header_params,
165
+ collection_formats))
166
+
167
+ # path parameters
168
+ if path_params:
169
+ path_params = self.sanitize_for_serialization(path_params)
170
+ path_params = self.parameters_to_tuples(path_params,
171
+ collection_formats)
172
+ for k, v in path_params:
173
+ # specified safe chars, encode everything
174
+ resource_path = resource_path.replace(
175
+ '{%s}' % k,
176
+ quote(str(v), safe=config.safe_chars_for_path_param)
177
+ )
178
+
179
+ # post parameters
180
+ if post_params or files:
181
+ post_params = post_params if post_params else []
182
+ post_params = self.sanitize_for_serialization(post_params)
183
+ post_params = self.parameters_to_tuples(post_params,
184
+ collection_formats)
185
+ post_params.extend(self.files_parameters(files))
186
+
187
+ # auth setting
188
+ self.update_params_for_auth(
189
+ header_params, query_params, auth_settings,
190
+ resource_path, method, body,
191
+ request_auth=_request_auth)
192
+
193
+ # body
194
+ if body:
195
+ body = self.sanitize_for_serialization(body)
196
+
197
+ # request url
198
+ if _host is None:
199
+ url = self.configuration.host + resource_path
200
+ else:
201
+ # use server/host defined in path or operation instead
202
+ url = _host + resource_path
203
+
204
+ # query parameters
205
+ if query_params:
206
+ query_params = self.sanitize_for_serialization(query_params)
207
+ url_query = self.parameters_to_url_query(query_params,
208
+ collection_formats)
209
+ url += "?" + url_query
210
+
211
+ try:
212
+ # perform request and return response
213
+ response_data = self.request(
214
+ method, url,
215
+ query_params=query_params,
216
+ headers=header_params,
217
+ post_params=post_params, body=body,
218
+ _preload_content=_preload_content,
219
+ _request_timeout=_request_timeout)
220
+ except ApiException as e:
221
+ if e.body:
222
+ e.body = e.body.decode('utf-8')
223
+ raise e
224
+
225
+ self.last_response = response_data
226
+
227
+ return_data = None # assuming deserialization is not needed
228
+ # data needs deserialization or returns HTTP data (deserialized) only
229
+ if _preload_content or _return_http_data_only:
230
+ response_type = response_types_map.get(str(response_data.status), None)
231
+ if not response_type and isinstance(response_data.status, int) and 100 <= response_data.status <= 599:
232
+ # if not found, look for '1XX', '2XX', etc.
233
+ response_type = response_types_map.get(str(response_data.status)[0] + "XX", None)
234
+
235
+ if response_type == "bytearray":
236
+ response_data.data = response_data.data
237
+ else:
238
+ match = None
239
+ content_type = response_data.getheader('content-type')
240
+ if content_type is not None:
241
+ match = re.search(r"charset=([a-zA-Z\-\d]+)[\s;]?", content_type)
242
+ encoding = match.group(1) if match else "utf-8"
243
+ response_data.data = response_data.data.decode(encoding)
244
+
245
+ # deserialize response data
246
+ if response_type == "bytearray":
247
+ return_data = response_data.data
248
+ elif response_type:
249
+ return_data = self.deserialize(response_data, response_type)
250
+ else:
251
+ return_data = None
252
+
253
+ if _return_http_data_only:
254
+ return return_data
255
+ else:
256
+ return ApiResponse(status_code = response_data.status,
257
+ data = return_data,
258
+ headers = response_data.getheaders(),
259
+ raw_data = response_data.data)
260
+
261
+ def sanitize_for_serialization(self, obj):
262
+ """Builds a JSON POST object.
263
+
264
+ If obj is None, return None.
265
+ If obj is SecretStr, return obj.get_secret_value()
266
+ If obj is str, int, long, float, bool, return directly.
267
+ If obj is datetime.datetime, datetime.date
268
+ convert to string in iso8601 format.
269
+ If obj is list, sanitize each element in the list.
270
+ If obj is dict, return the dict.
271
+ If obj is OpenAPI model, return the properties dict.
272
+
273
+ :param obj: The data to serialize.
274
+ :return: The serialized form of data.
275
+ """
276
+ if obj is None:
277
+ return None
278
+ elif isinstance(obj, SecretStr):
279
+ return obj.get_secret_value()
280
+ elif isinstance(obj, self.PRIMITIVE_TYPES):
281
+ return obj
282
+ elif isinstance(obj, list):
283
+ return [self.sanitize_for_serialization(sub_obj)
284
+ for sub_obj in obj]
285
+ elif isinstance(obj, tuple):
286
+ return tuple(self.sanitize_for_serialization(sub_obj)
287
+ for sub_obj in obj)
288
+ elif isinstance(obj, (datetime.datetime, datetime.date)):
289
+ return obj.isoformat()
290
+
291
+ if isinstance(obj, dict):
292
+ obj_dict = obj
293
+ else:
294
+ # Convert model obj to dict except
295
+ # attributes `openapi_types`, `attribute_map`
296
+ # and attributes which value is not None.
297
+ # Convert attribute name to json key in
298
+ # model definition for request.
299
+ if hasattr(obj, 'to_dict') and callable(getattr(obj, 'to_dict')):
300
+ obj_dict = obj.to_dict()
301
+ else:
302
+ obj_dict = obj.__dict__
303
+
304
+ return {key: self.sanitize_for_serialization(val)
305
+ for key, val in obj_dict.items()}
306
+
307
+ def deserialize(self, response, response_type):
308
+ """Deserializes response into an object.
309
+
310
+ :param response: RESTResponse object to be deserialized.
311
+ :param response_type: class literal for
312
+ deserialized object, or string of class name.
313
+
314
+ :return: deserialized object.
315
+ """
316
+ # handle file downloading
317
+ # save response body into a tmp file and return the instance
318
+ if response_type == "file":
319
+ return self.__deserialize_file(response)
320
+
321
+ # fetch data from response object
322
+ try:
323
+ data = json.loads(response.data)
324
+ except ValueError:
325
+ data = response.data
326
+
327
+ return self.__deserialize(data, response_type)
328
+
329
+ def __deserialize(self, data, klass):
330
+ """Deserializes dict, list, str into an object.
331
+
332
+ :param data: dict, list or str.
333
+ :param klass: class literal, or string of class name.
334
+
335
+ :return: object.
336
+ """
337
+ if data is None:
338
+ return None
339
+
340
+ if isinstance(klass, str):
341
+ if klass.startswith('List['):
342
+ sub_kls = re.match(r'List\[(.*)]', klass).group(1)
343
+ return [self.__deserialize(sub_data, sub_kls)
344
+ for sub_data in data]
345
+
346
+ if klass.startswith('Dict['):
347
+ sub_kls = re.match(r'Dict\[([^,]*), (.*)]', klass).group(2)
348
+ return {k: self.__deserialize(v, sub_kls)
349
+ for k, v in data.items()}
350
+
351
+ # convert str to class
352
+ if klass in self.NATIVE_TYPES_MAPPING:
353
+ klass = self.NATIVE_TYPES_MAPPING[klass]
354
+ else:
355
+ klass = getattr(cbbd.models, klass)
356
+
357
+ if klass in self.PRIMITIVE_TYPES:
358
+ return self.__deserialize_primitive(data, klass)
359
+ elif klass == object:
360
+ return self.__deserialize_object(data)
361
+ elif klass == datetime.date:
362
+ return self.__deserialize_date(data)
363
+ elif klass == datetime.datetime:
364
+ return self.__deserialize_datetime(data)
365
+ else:
366
+ return self.__deserialize_model(data, klass)
367
+
368
+ def call_api(self, resource_path, method,
369
+ path_params=None, query_params=None, header_params=None,
370
+ body=None, post_params=None, files=None,
371
+ response_types_map=None, auth_settings=None,
372
+ async_req=None, _return_http_data_only=None,
373
+ collection_formats=None, _preload_content=True,
374
+ _request_timeout=None, _host=None, _request_auth=None):
375
+ """Makes the HTTP request (synchronous) and returns deserialized data.
376
+
377
+ To make an async_req request, set the async_req parameter.
378
+
379
+ :param resource_path: Path to method endpoint.
380
+ :param method: Method to call.
381
+ :param path_params: Path parameters in the url.
382
+ :param query_params: Query parameters in the url.
383
+ :param header_params: Header parameters to be
384
+ placed in the request header.
385
+ :param body: Request body.
386
+ :param post_params dict: Request post form parameters,
387
+ for `application/x-www-form-urlencoded`, `multipart/form-data`.
388
+ :param auth_settings list: Auth Settings names for the request.
389
+ :param response: Response data type.
390
+ :param files dict: key -> filename, value -> filepath,
391
+ for `multipart/form-data`.
392
+ :param async_req bool: execute request asynchronously
393
+ :param _return_http_data_only: response data instead of ApiResponse
394
+ object with status code, headers, etc
395
+ :param _preload_content: if False, the ApiResponse.data will
396
+ be set to none and raw_data will store the
397
+ HTTP response body without reading/decoding.
398
+ Default is True.
399
+ :param collection_formats: dict of collection formats for path, query,
400
+ header, and post parameters.
401
+ :param _request_timeout: timeout setting for this request. If one
402
+ number provided, it will be total request
403
+ timeout. It can also be a pair (tuple) of
404
+ (connection, read) timeouts.
405
+ :param _request_auth: set to override the auth_settings for an a single
406
+ request; this effectively ignores the authentication
407
+ in the spec for a single request.
408
+ :type _request_token: dict, optional
409
+ :return:
410
+ If async_req parameter is True,
411
+ the request will be called asynchronously.
412
+ The method will return the request thread.
413
+ If parameter async_req is False or missing,
414
+ then the method will return the response directly.
415
+ """
416
+ args = (
417
+ resource_path,
418
+ method,
419
+ path_params,
420
+ query_params,
421
+ header_params,
422
+ body,
423
+ post_params,
424
+ files,
425
+ response_types_map,
426
+ auth_settings,
427
+ _return_http_data_only,
428
+ collection_formats,
429
+ _preload_content,
430
+ _request_timeout,
431
+ _host,
432
+ _request_auth,
433
+ )
434
+ if not async_req:
435
+ return self.__call_api(*args)
436
+
437
+ return self.pool.apply_async(self.__call_api, args)
438
+
439
+ def request(self, method, url, query_params=None, headers=None,
440
+ post_params=None, body=None, _preload_content=True,
441
+ _request_timeout=None):
442
+ """Makes the HTTP request using RESTClient."""
443
+ if method == "GET":
444
+ return self.rest_client.get_request(url,
445
+ query_params=query_params,
446
+ _preload_content=_preload_content,
447
+ _request_timeout=_request_timeout,
448
+ headers=headers)
449
+ elif method == "HEAD":
450
+ return self.rest_client.head_request(url,
451
+ query_params=query_params,
452
+ _preload_content=_preload_content,
453
+ _request_timeout=_request_timeout,
454
+ headers=headers)
455
+ elif method == "OPTIONS":
456
+ return self.rest_client.options_request(url,
457
+ query_params=query_params,
458
+ headers=headers,
459
+ _preload_content=_preload_content,
460
+ _request_timeout=_request_timeout)
461
+ elif method == "POST":
462
+ return self.rest_client.post_request(url,
463
+ query_params=query_params,
464
+ headers=headers,
465
+ post_params=post_params,
466
+ _preload_content=_preload_content,
467
+ _request_timeout=_request_timeout,
468
+ body=body)
469
+ elif method == "PUT":
470
+ return self.rest_client.put_request(url,
471
+ query_params=query_params,
472
+ headers=headers,
473
+ post_params=post_params,
474
+ _preload_content=_preload_content,
475
+ _request_timeout=_request_timeout,
476
+ body=body)
477
+ elif method == "PATCH":
478
+ return self.rest_client.patch_request(url,
479
+ query_params=query_params,
480
+ headers=headers,
481
+ post_params=post_params,
482
+ _preload_content=_preload_content,
483
+ _request_timeout=_request_timeout,
484
+ body=body)
485
+ elif method == "DELETE":
486
+ return self.rest_client.delete_request(url,
487
+ query_params=query_params,
488
+ headers=headers,
489
+ _preload_content=_preload_content,
490
+ _request_timeout=_request_timeout,
491
+ body=body)
492
+ else:
493
+ raise ApiValueError(
494
+ "http method must be `GET`, `HEAD`, `OPTIONS`,"
495
+ " `POST`, `PATCH`, `PUT` or `DELETE`."
496
+ )
497
+
498
+ def parameters_to_tuples(self, params, collection_formats):
499
+ """Get parameters as list of tuples, formatting collections.
500
+
501
+ :param params: Parameters as dict or list of two-tuples
502
+ :param dict collection_formats: Parameter collection formats
503
+ :return: Parameters as list of tuples, collections formatted
504
+ """
505
+ new_params = []
506
+ if collection_formats is None:
507
+ collection_formats = {}
508
+ for k, v in params.items() if isinstance(params, dict) else params: # noqa: E501
509
+ if k in collection_formats:
510
+ collection_format = collection_formats[k]
511
+ if collection_format == 'multi':
512
+ new_params.extend((k, value) for value in v)
513
+ else:
514
+ if collection_format == 'ssv':
515
+ delimiter = ' '
516
+ elif collection_format == 'tsv':
517
+ delimiter = '\t'
518
+ elif collection_format == 'pipes':
519
+ delimiter = '|'
520
+ else: # csv is the default
521
+ delimiter = ','
522
+ new_params.append(
523
+ (k, delimiter.join(str(value) for value in v)))
524
+ else:
525
+ new_params.append((k, v))
526
+ return new_params
527
+
528
+ def parameters_to_url_query(self, params, collection_formats):
529
+ """Get parameters as list of tuples, formatting collections.
530
+
531
+ :param params: Parameters as dict or list of two-tuples
532
+ :param dict collection_formats: Parameter collection formats
533
+ :return: URL query string (e.g. a=Hello%20World&b=123)
534
+ """
535
+ new_params = []
536
+ if collection_formats is None:
537
+ collection_formats = {}
538
+ for k, v in params.items() if isinstance(params, dict) else params: # noqa: E501
539
+ if isinstance(v, bool):
540
+ v = str(v).lower()
541
+ if isinstance(v, (int, float)):
542
+ v = str(v)
543
+ if isinstance(v, dict):
544
+ v = json.dumps(v)
545
+
546
+ if k in collection_formats:
547
+ collection_format = collection_formats[k]
548
+ if collection_format == 'multi':
549
+ new_params.extend((k, str(value)) for value in v)
550
+ else:
551
+ if collection_format == 'ssv':
552
+ delimiter = ' '
553
+ elif collection_format == 'tsv':
554
+ delimiter = '\t'
555
+ elif collection_format == 'pipes':
556
+ delimiter = '|'
557
+ else: # csv is the default
558
+ delimiter = ','
559
+ new_params.append(
560
+ (k, delimiter.join(quote(str(value)) for value in v)))
561
+ else:
562
+ new_params.append((k, quote(str(v))))
563
+
564
+ return "&".join(["=".join(map(str, item)) for item in new_params])
565
+
566
+ def files_parameters(self, files=None):
567
+ """Builds form parameters.
568
+
569
+ :param files: File parameters.
570
+ :return: Form parameters with files.
571
+ """
572
+ params = []
573
+
574
+ if files:
575
+ for k, v in files.items():
576
+ if not v:
577
+ continue
578
+ file_names = v if type(v) is list else [v]
579
+ for n in file_names:
580
+ with open(n, 'rb') as f:
581
+ filename = os.path.basename(f.name)
582
+ filedata = f.read()
583
+ mimetype = (mimetypes.guess_type(filename)[0] or
584
+ 'application/octet-stream')
585
+ params.append(
586
+ tuple([k, tuple([filename, filedata, mimetype])]))
587
+
588
+ return params
589
+
590
+ def select_header_accept(self, accepts):
591
+ """Returns `Accept` based on an array of accepts provided.
592
+
593
+ :param accepts: List of headers.
594
+ :return: Accept (e.g. application/json).
595
+ """
596
+ if not accepts:
597
+ return
598
+
599
+ for accept in accepts:
600
+ if re.search('json', accept, re.IGNORECASE):
601
+ return accept
602
+
603
+ return accepts[0]
604
+
605
+ def select_header_content_type(self, content_types):
606
+ """Returns `Content-Type` based on an array of content_types provided.
607
+
608
+ :param content_types: List of content-types.
609
+ :return: Content-Type (e.g. application/json).
610
+ """
611
+ if not content_types:
612
+ return None
613
+
614
+ for content_type in content_types:
615
+ if re.search('json', content_type, re.IGNORECASE):
616
+ return content_type
617
+
618
+ return content_types[0]
619
+
620
+ def update_params_for_auth(self, headers, queries, auth_settings,
621
+ resource_path, method, body,
622
+ request_auth=None):
623
+ """Updates header and query params based on authentication setting.
624
+
625
+ :param headers: Header parameters dict to be updated.
626
+ :param queries: Query parameters tuple list to be updated.
627
+ :param auth_settings: Authentication setting identifiers list.
628
+ :resource_path: A string representation of the HTTP request resource path.
629
+ :method: A string representation of the HTTP request method.
630
+ :body: A object representing the body of the HTTP request.
631
+ The object type is the return value of sanitize_for_serialization().
632
+ :param request_auth: if set, the provided settings will
633
+ override the token in the configuration.
634
+ """
635
+ if not auth_settings:
636
+ return
637
+
638
+ if request_auth:
639
+ self._apply_auth_params(headers, queries,
640
+ resource_path, method, body,
641
+ request_auth)
642
+ return
643
+
644
+ for auth in auth_settings:
645
+ auth_setting = self.configuration.auth_settings().get(auth)
646
+ if auth_setting:
647
+ self._apply_auth_params(headers, queries,
648
+ resource_path, method, body,
649
+ auth_setting)
650
+
651
+ def _apply_auth_params(self, headers, queries,
652
+ resource_path, method, body,
653
+ auth_setting):
654
+ """Updates the request parameters based on a single auth_setting
655
+
656
+ :param headers: Header parameters dict to be updated.
657
+ :param queries: Query parameters tuple list to be updated.
658
+ :resource_path: A string representation of the HTTP request resource path.
659
+ :method: A string representation of the HTTP request method.
660
+ :body: A object representing the body of the HTTP request.
661
+ The object type is the return value of sanitize_for_serialization().
662
+ :param auth_setting: auth settings for the endpoint
663
+ """
664
+ if auth_setting['in'] == 'cookie':
665
+ headers['Cookie'] = auth_setting['value']
666
+ elif auth_setting['in'] == 'header':
667
+ if auth_setting['type'] != 'http-signature':
668
+ headers[auth_setting['key']] = auth_setting['value']
669
+ elif auth_setting['in'] == 'query':
670
+ queries.append((auth_setting['key'], auth_setting['value']))
671
+ else:
672
+ raise ApiValueError(
673
+ 'Authentication token must be in `query` or `header`'
674
+ )
675
+
676
+ def __deserialize_file(self, response):
677
+ """Deserializes body to file
678
+
679
+ Saves response body into a file in a temporary folder,
680
+ using the filename from the `Content-Disposition` header if provided.
681
+
682
+ :param response: RESTResponse.
683
+ :return: file path.
684
+ """
685
+ fd, path = tempfile.mkstemp(dir=self.configuration.temp_folder_path)
686
+ os.close(fd)
687
+ os.remove(path)
688
+
689
+ content_disposition = response.getheader("Content-Disposition")
690
+ if content_disposition:
691
+ filename = re.search(r'filename=[\'"]?([^\'"\s]+)[\'"]?',
692
+ content_disposition).group(1)
693
+ path = os.path.join(os.path.dirname(path), filename)
694
+
695
+ with open(path, "wb") as f:
696
+ f.write(response.data)
697
+
698
+ return path
699
+
700
+ def __deserialize_primitive(self, data, klass):
701
+ """Deserializes string to primitive type.
702
+
703
+ :param data: str.
704
+ :param klass: class literal.
705
+
706
+ :return: int, long, float, str, bool.
707
+ """
708
+ try:
709
+ return klass(data)
710
+ except UnicodeEncodeError:
711
+ return str(data)
712
+ except TypeError:
713
+ return data
714
+
715
+ def __deserialize_object(self, value):
716
+ """Return an original value.
717
+
718
+ :return: object.
719
+ """
720
+ return value
721
+
722
+ def __deserialize_date(self, string):
723
+ """Deserializes string to date.
724
+
725
+ :param string: str.
726
+ :return: date.
727
+ """
728
+ try:
729
+ return parse(string).date()
730
+ except ImportError:
731
+ return string
732
+ except ValueError:
733
+ raise rest.ApiException(
734
+ status=0,
735
+ reason="Failed to parse `{0}` as date object".format(string)
736
+ )
737
+
738
+ def __deserialize_datetime(self, string):
739
+ """Deserializes string to datetime.
740
+
741
+ The string should be in iso8601 datetime format.
742
+
743
+ :param string: str.
744
+ :return: datetime.
745
+ """
746
+ try:
747
+ return parse(string)
748
+ except ImportError:
749
+ return string
750
+ except ValueError:
751
+ raise rest.ApiException(
752
+ status=0,
753
+ reason=(
754
+ "Failed to parse `{0}` as datetime object"
755
+ .format(string)
756
+ )
757
+ )
758
+
759
+ def __deserialize_model(self, data, klass):
760
+ """Deserializes list or dict to model.
761
+
762
+ :param data: dict, list.
763
+ :param klass: class literal.
764
+ :return: model object.
765
+ """
766
+
767
+ return klass.from_dict(data)