1
- # coding: utf-8
2
-
3
- """
4
- Copyright 2016 SmartBear Software
5
-
6
- Licensed under the Apache License, Version 2.0 (the "License");
7
- you may not use this file except in compliance with the License.
8
- You may obtain a copy of the License at
9
-
10
- http://www.apache.org/licenses/LICENSE-2.0
11
-
12
- Unless required by applicable law or agreed to in writing, software
13
- distributed under the License is distributed on an "AS IS" BASIS,
14
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
- See the License for the specific language governing permissions and
16
- limitations under the License.
17
-
18
- ref: https://github.com/swagger-api/swagger-codegen
19
- """
1
+ # Copyright 2016 The Kubernetes Authors.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ # this file is first auto-generated by swagger-codegen and then modified to
16
+ # handle specific cases of kubernetes. It will not be overwritten on client
17
+ # generation.
20
18
21
19
from __future__ import absolute_import
22
20
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
30
21
import json
31
22
import mimetypes
23
+ import os
24
+ import re
32
25
import tempfile
33
26
import threading
34
-
35
- from datetime import datetime
36
- from datetime import date
27
+ from datetime import date , datetime
37
28
38
29
# python 2 and python 3 compatibility library
39
30
from six import PY3 , integer_types , iteritems , text_type
40
31
from six .moves .urllib .parse import quote
41
32
33
+ from . import models , ws_client
42
34
from .configuration import configuration
35
+ from .rest import ApiException , RESTClientObject
43
36
44
37
45
38
class ApiClient (object ):
@@ -59,9 +52,9 @@ class ApiClient(object):
59
52
:param header_name: a header to pass when making calls to the API.
60
53
:param header_value: a header value to pass when making calls to the API.
61
54
"""
55
+
62
56
def __init__ (self , host = None , header_name = None , header_value = None ,
63
57
cookie = None , config = configuration ):
64
-
65
58
"""
66
59
Constructor of the class.
67
60
"""
@@ -99,8 +92,8 @@ def __call_api(self, resource_path, method,
99
92
path_params = None , query_params = None , header_params = None ,
100
93
body = None , post_params = None , files = None ,
101
94
response_type = None , auth_settings = None , callback = None ,
102
- _return_http_data_only = None , collection_formats = None , _preload_content = True ,
103
- _request_timeout = None ):
95
+ _return_http_data_only = None , collection_formats = None ,
96
+ _preload_content = True , _request_timeout = None ):
104
97
105
98
# header parameters
106
99
header_params = header_params or {}
@@ -163,11 +156,16 @@ def __call_api(self, resource_path, method,
163
156
return_data = None
164
157
165
158
if callback :
166
- callback (return_data ) if _return_http_data_only else callback ((return_data , response_data .status , response_data .getheaders ()))
159
+ if _return_http_data_only :
160
+ callback (return_data )
161
+ else :
162
+ callback ((return_data ,
163
+ response_data .status , response_data .getheaders ()))
167
164
elif _return_http_data_only :
168
165
return (return_data )
169
166
else :
170
- return (return_data , response_data .status , response_data .getheaders ())
167
+ return (return_data , response_data .status ,
168
+ response_data .getheaders ())
171
169
172
170
def sanitize_for_serialization (self , obj ):
173
171
"""
@@ -194,7 +192,7 @@ def sanitize_for_serialization(self, obj):
194
192
for sub_obj in obj ]
195
193
elif isinstance (obj , tuple ):
196
194
return tuple (self .sanitize_for_serialization (sub_obj )
197
- for sub_obj in obj )
195
+ for sub_obj in obj )
198
196
elif isinstance (obj , (datetime , date )):
199
197
return obj .isoformat ()
200
198
else :
@@ -248,7 +246,7 @@ def __deserialize(self, data, klass):
248
246
if data is None :
249
247
return None
250
248
251
- if type (klass ) == str :
249
+ if isinstance (klass , str ) :
252
250
if klass .startswith ('list[' ):
253
251
sub_kls = re .match ('list\[(.*)\]' , klass ).group (1 )
254
252
return [self .__deserialize (sub_data , sub_kls )
@@ -285,8 +283,8 @@ def call_api(self, resource_path, method,
285
283
path_params = None , query_params = None , header_params = None ,
286
284
body = None , post_params = None , files = None ,
287
285
response_type = None , auth_settings = None , callback = None ,
288
- _return_http_data_only = None , collection_formats = None , _preload_content = True ,
289
- _request_timeout = None ):
286
+ _return_http_data_only = None , collection_formats = None ,
287
+ _preload_content = True , _request_timeout = None ):
290
288
"""
291
289
Makes the HTTP request (synchronous) and return the deserialized data.
292
290
To make an async request, define a function for callback.
@@ -307,13 +305,18 @@ def call_api(self, resource_path, method,
307
305
:param callback function: Callback function for asynchronous request.
308
306
If provide this parameter,
309
307
the request will be called asynchronously.
310
- :param _return_http_data_only: response data without head status code and headers
308
+ :param _return_http_data_only: response data without head status code
309
+ and headers
311
310
:param collection_formats: dict of collection formats for path, query,
312
311
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.
312
+ :param _preload_content: if False, the urllib3.HTTPResponse object will
313
+ be returned without
314
+ reading/decoding response data.
315
+ Default is True.
316
+ :param _request_timeout: timeout setting for this request. If one
317
+ number provided, it will be total request
318
+ timeout. It can also be a pair (tuple) of
319
+ (connection, read) timeouts.
317
320
:return:
318
321
If provide parameter callback,
319
322
the request will be called asynchronously.
@@ -326,7 +329,8 @@ def call_api(self, resource_path, method,
326
329
path_params , query_params , header_params ,
327
330
body , post_params , files ,
328
331
response_type , auth_settings , callback ,
329
- _return_http_data_only , collection_formats , _preload_content , _request_timeout )
332
+ _return_http_data_only , collection_formats ,
333
+ _preload_content , _request_timeout )
330
334
else :
331
335
thread = threading .Thread (target = self .__call_api ,
332
336
args = (resource_path , method ,
@@ -335,18 +339,22 @@ def call_api(self, resource_path, method,
335
339
post_params , files ,
336
340
response_type , auth_settings ,
337
341
callback , _return_http_data_only ,
338
- collection_formats , _preload_content , _request_timeout ))
342
+ collection_formats ,
343
+ _preload_content ,
344
+ _request_timeout ))
339
345
thread .start ()
340
346
return thread
341
347
342
348
def request (self , method , url , query_params = None , headers = None ,
343
- post_params = None , body = None , _preload_content = True , _request_timeout = None ):
349
+ post_params = None , body = None , _preload_content = True ,
350
+ _request_timeout = None ):
344
351
"""
345
352
Makes the HTTP request using RESTClient.
346
353
"""
347
354
# FIXME(dims) : We need a better way to figure out which
348
355
# calls end up using web sockets
349
- if (url .endswith ('/exec' ) or url .endswith ('/attach' )) and (method == "GET" or method == "POST" ):
356
+ if (url .endswith ('/exec' ) or url .endswith ('/attach' )) and \
357
+ (method == "GET" or method == "POST" ):
350
358
return ws_client .websocket_call (self .config ,
351
359
url ,
352
360
query_params = query_params ,
@@ -458,14 +466,15 @@ def prepare_post_parameters(self, post_params=None, files=None):
458
466
for k , v in iteritems (files ):
459
467
if not v :
460
468
continue
461
- file_names = v if type ( v ) is list else [v ]
469
+ file_names = v if isinstance ( v , list ) else [v ]
462
470
for n in file_names :
463
471
with open (n , 'rb' ) as f :
464
472
filename = os .path .basename (f .name )
465
473
filedata = f .read ()
466
- mimetype = mimetypes .\
467
- guess_type (filename )[0 ] or 'application/octet-stream'
468
- params .append (tuple ([k , tuple ([filename , filedata , mimetype ])]))
474
+ mimetype = (mimetypes .guess_type (filename )[0 ] or
475
+ 'application/octet-stream' )
476
+ params .append (tuple ([k , tuple ([filename , filedata ,
477
+ mimetype ])]))
469
478
470
479
return params
471
480
@@ -543,9 +552,8 @@ def __deserialize_file(self, response):
543
552
544
553
content_disposition = response .getheader ("Content-Disposition" )
545
554
if content_disposition :
546
- filename = re .\
547
- search (r'filename=[\'"]?([^\'"\s]+)[\'"]?' , content_disposition ).\
548
- group (1 )
555
+ filename = re .search (r'filename=[\'"]?([^\'"\s]+)[\'"]?' ,
556
+ content_disposition ).group (1 )
549
557
path = os .path .join (os .path .dirname (path ), filename )
550
558
551
559
with open (path , "w" ) as f :
0 commit comments