2020
2121from __future__ import absolute_import
2222
23- from . import models
24- from . import ws_client
25- from .rest import RESTClientObject
26- from .rest import ApiException
27-
28- import os
29- import re
3023import json
3124import mimetypes
25+ import os
26+ import re
3227import tempfile
3328import threading
34-
35- from datetime import datetime
36- from datetime import date
29+ from datetime import date , datetime
3730
3831# python 2 and python 3 compatibility library
3932from six import PY3 , integer_types , iteritems , text_type
4033from six .moves .urllib .parse import quote
4134
35+ from . import models , ws_client
4236from .configuration import configuration
37+ from .rest import ApiException , RESTClientObject
4338
4439
4540class ApiClient (object ):
@@ -59,9 +54,9 @@ class ApiClient(object):
5954 :param header_name: a header to pass when making calls to the API.
6055 :param header_value: a header value to pass when making calls to the API.
6156 """
57+
6258 def __init__ (self , host = None , header_name = None , header_value = None ,
6359 cookie = None , config = configuration ):
64-
6560 """
6661 Constructor of the class.
6762 """
@@ -99,8 +94,8 @@ def __call_api(self, resource_path, method,
9994 path_params = None , query_params = None , header_params = None ,
10095 body = None , post_params = None , files = None ,
10196 response_type = None , auth_settings = None , callback = None ,
102- _return_http_data_only = None , collection_formats = None , _preload_content = True ,
103- _request_timeout = None ):
97+ _return_http_data_only = None , collection_formats = None ,
98+ _preload_content = True , _request_timeout = None ):
10499
105100 # header parameters
106101 header_params = header_params or {}
@@ -163,11 +158,16 @@ def __call_api(self, resource_path, method,
163158 return_data = None
164159
165160 if callback :
166- callback (return_data ) if _return_http_data_only else callback ((return_data , response_data .status , response_data .getheaders ()))
161+ if _return_http_data_only :
162+ callback (return_data )
163+ else :
164+ callback ((return_data ,
165+ response_data .status , response_data .getheaders ()))
167166 elif _return_http_data_only :
168167 return (return_data )
169168 else :
170- return (return_data , response_data .status , response_data .getheaders ())
169+ return (return_data , response_data .status ,
170+ response_data .getheaders ())
171171
172172 def sanitize_for_serialization (self , obj ):
173173 """
@@ -194,7 +194,7 @@ def sanitize_for_serialization(self, obj):
194194 for sub_obj in obj ]
195195 elif isinstance (obj , tuple ):
196196 return tuple (self .sanitize_for_serialization (sub_obj )
197- for sub_obj in obj )
197+ for sub_obj in obj )
198198 elif isinstance (obj , (datetime , date )):
199199 return obj .isoformat ()
200200 else :
@@ -248,7 +248,7 @@ def __deserialize(self, data, klass):
248248 if data is None :
249249 return None
250250
251- if type (klass ) == str :
251+ if isinstance (klass , str ) :
252252 if klass .startswith ('list[' ):
253253 sub_kls = re .match ('list\[(.*)\]' , klass ).group (1 )
254254 return [self .__deserialize (sub_data , sub_kls )
@@ -285,8 +285,8 @@ def call_api(self, resource_path, method,
285285 path_params = None , query_params = None , header_params = None ,
286286 body = None , post_params = None , files = None ,
287287 response_type = None , auth_settings = None , callback = None ,
288- _return_http_data_only = None , collection_formats = None , _preload_content = True ,
289- _request_timeout = None ):
288+ _return_http_data_only = None , collection_formats = None ,
289+ _preload_content = True , _request_timeout = None ):
290290 """
291291 Makes the HTTP request (synchronous) and return the deserialized data.
292292 To make an async request, define a function for callback.
@@ -307,13 +307,18 @@ def call_api(self, resource_path, method,
307307 :param callback function: Callback function for asynchronous request.
308308 If provide this parameter,
309309 the request will be called asynchronously.
310- :param _return_http_data_only: response data without head status code and headers
310+ :param _return_http_data_only: response data without head status code
311+ and headers
311312 :param collection_formats: dict of collection formats for path, query,
312313 header, and post parameters.
313- :param _preload_content: if False, the urllib3.HTTPResponse object will be returned without
314- reading/decoding response data. Default is True.
315- :param _request_timeout: timeout setting for this request. If one number provided, it will be total request
316- timeout. It can also be a pair (tuple) of (connection, read) timeouts.
314+ :param _preload_content: if False, the urllib3.HTTPResponse object will
315+ be returned without
316+ reading/decoding response data.
317+ Default is True.
318+ :param _request_timeout: timeout setting for this request. If one
319+ number provided, it will be total request
320+ timeout. It can also be a pair (tuple) of
321+ (connection, read) timeouts.
317322 :return:
318323 If provide parameter callback,
319324 the request will be called asynchronously.
@@ -326,7 +331,8 @@ def call_api(self, resource_path, method,
326331 path_params , query_params , header_params ,
327332 body , post_params , files ,
328333 response_type , auth_settings , callback ,
329- _return_http_data_only , collection_formats , _preload_content , _request_timeout )
334+ _return_http_data_only , collection_formats ,
335+ _preload_content , _request_timeout )
330336 else :
331337 thread = threading .Thread (target = self .__call_api ,
332338 args = (resource_path , method ,
@@ -335,18 +341,22 @@ def call_api(self, resource_path, method,
335341 post_params , files ,
336342 response_type , auth_settings ,
337343 callback , _return_http_data_only ,
338- collection_formats , _preload_content , _request_timeout ))
344+ collection_formats ,
345+ _preload_content ,
346+ _request_timeout ))
339347 thread .start ()
340348 return thread
341349
342350 def request (self , method , url , query_params = None , headers = None ,
343- post_params = None , body = None , _preload_content = True , _request_timeout = None ):
351+ post_params = None , body = None , _preload_content = True ,
352+ _request_timeout = None ):
344353 """
345354 Makes the HTTP request using RESTClient.
346355 """
347356 # FIXME(dims) : We need a better way to figure out which
348357 # calls end up using web sockets
349- if (url .endswith ('/exec' ) or url .endswith ('/attach' )) and (method == "GET" or method == "POST" ):
358+ if (url .endswith ('/exec' ) or url .endswith ('/attach' )) and \
359+ (method == "GET" or method == "POST" ):
350360 return ws_client .websocket_call (self .config ,
351361 url ,
352362 query_params = query_params ,
@@ -458,14 +468,15 @@ def prepare_post_parameters(self, post_params=None, files=None):
458468 for k , v in iteritems (files ):
459469 if not v :
460470 continue
461- file_names = v if type ( v ) is list else [v ]
471+ file_names = v if isinstance ( v , list ) else [v ]
462472 for n in file_names :
463473 with open (n , 'rb' ) as f :
464474 filename = os .path .basename (f .name )
465475 filedata = f .read ()
466- mimetype = mimetypes .\
467- guess_type (filename )[0 ] or 'application/octet-stream'
468- params .append (tuple ([k , tuple ([filename , filedata , mimetype ])]))
476+ mimetype = (mimetypes .guess_type (filename )[0 ] or
477+ 'application/octet-stream' )
478+ params .append (tuple ([k , tuple ([filename , filedata ,
479+ mimetype ])]))
469480
470481 return params
471482
@@ -543,9 +554,8 @@ def __deserialize_file(self, response):
543554
544555 content_disposition = response .getheader ("Content-Disposition" )
545556 if content_disposition :
546- filename = re .\
547- search (r'filename=[\'"]?([^\'"\s]+)[\'"]?' , content_disposition ).\
548- group (1 )
557+ filename = re .search (r'filename=[\'"]?([^\'"\s]+)[\'"]?' ,
558+ content_disposition ).group (1 )
549559 path = os .path .join (os .path .dirname (path ), filename )
550560
551561 with open (path , "w" ) as f :
0 commit comments