Skip to content
This repository was archived by the owner on Mar 13, 2022. It is now read-only.

Commit ca6626a

Browse files
committed
Update pep8
1 parent ecaaa7b commit ca6626a

File tree

4 files changed

+177
-169
lines changed

4 files changed

+177
-169
lines changed

api_client.py

+62-54
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,38 @@
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.
2018

2119
from __future__ import absolute_import
2220

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
3021
import json
3122
import mimetypes
23+
import os
24+
import re
3225
import tempfile
3326
import threading
34-
35-
from datetime import datetime
36-
from datetime import date
27+
from datetime import date, datetime
3728

3829
# python 2 and python 3 compatibility library
3930
from six import PY3, integer_types, iteritems, text_type
4031
from six.moves.urllib.parse import quote
4132

33+
from . import models, ws_client
4234
from .configuration import configuration
35+
from .rest import ApiException, RESTClientObject
4336

4437

4538
class ApiClient(object):
@@ -59,9 +52,9 @@ class ApiClient(object):
5952
:param header_name: a header to pass when making calls to the API.
6053
:param header_value: a header value to pass when making calls to the API.
6154
"""
55+
6256
def __init__(self, host=None, header_name=None, header_value=None,
6357
cookie=None, config=configuration):
64-
6558
"""
6659
Constructor of the class.
6760
"""
@@ -99,8 +92,8 @@ def __call_api(self, resource_path, method,
9992
path_params=None, query_params=None, header_params=None,
10093
body=None, post_params=None, files=None,
10194
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):
10497

10598
# header parameters
10699
header_params = header_params or {}
@@ -163,11 +156,16 @@ def __call_api(self, resource_path, method,
163156
return_data = None
164157

165158
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()))
167164
elif _return_http_data_only:
168165
return (return_data)
169166
else:
170-
return (return_data, response_data.status, response_data.getheaders())
167+
return (return_data, response_data.status,
168+
response_data.getheaders())
171169

172170
def sanitize_for_serialization(self, obj):
173171
"""
@@ -194,7 +192,7 @@ def sanitize_for_serialization(self, obj):
194192
for sub_obj in obj]
195193
elif isinstance(obj, tuple):
196194
return tuple(self.sanitize_for_serialization(sub_obj)
197-
for sub_obj in obj)
195+
for sub_obj in obj)
198196
elif isinstance(obj, (datetime, date)):
199197
return obj.isoformat()
200198
else:
@@ -248,7 +246,7 @@ def __deserialize(self, data, klass):
248246
if data is None:
249247
return None
250248

251-
if type(klass) == str:
249+
if isinstance(klass, str):
252250
if klass.startswith('list['):
253251
sub_kls = re.match('list\[(.*)\]', klass).group(1)
254252
return [self.__deserialize(sub_data, sub_kls)
@@ -285,8 +283,8 @@ def call_api(self, resource_path, method,
285283
path_params=None, query_params=None, header_params=None,
286284
body=None, post_params=None, files=None,
287285
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):
290288
"""
291289
Makes the HTTP request (synchronous) and return the deserialized data.
292290
To make an async request, define a function for callback.
@@ -307,13 +305,18 @@ def call_api(self, resource_path, method,
307305
:param callback function: Callback function for asynchronous request.
308306
If provide this parameter,
309307
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
311310
:param collection_formats: dict of collection formats for path, query,
312311
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.
317320
:return:
318321
If provide parameter callback,
319322
the request will be called asynchronously.
@@ -326,7 +329,8 @@ def call_api(self, resource_path, method,
326329
path_params, query_params, header_params,
327330
body, post_params, files,
328331
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)
330334
else:
331335
thread = threading.Thread(target=self.__call_api,
332336
args=(resource_path, method,
@@ -335,18 +339,22 @@ def call_api(self, resource_path, method,
335339
post_params, files,
336340
response_type, auth_settings,
337341
callback, _return_http_data_only,
338-
collection_formats, _preload_content, _request_timeout))
342+
collection_formats,
343+
_preload_content,
344+
_request_timeout))
339345
thread.start()
340346
return thread
341347

342348
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):
344351
"""
345352
Makes the HTTP request using RESTClient.
346353
"""
347354
# FIXME(dims) : We need a better way to figure out which
348355
# 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"):
350358
return ws_client.websocket_call(self.config,
351359
url,
352360
query_params=query_params,
@@ -458,14 +466,15 @@ def prepare_post_parameters(self, post_params=None, files=None):
458466
for k, v in iteritems(files):
459467
if not v:
460468
continue
461-
file_names = v if type(v) is list else [v]
469+
file_names = v if isinstance(v, list) else [v]
462470
for n in file_names:
463471
with open(n, 'rb') as f:
464472
filename = os.path.basename(f.name)
465473
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])]))
469478

470479
return params
471480

@@ -543,9 +552,8 @@ def __deserialize_file(self, response):
543552

544553
content_disposition = response.getheader("Content-Disposition")
545554
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)
549557
path = os.path.join(os.path.dirname(path), filename)
550558

551559
with open(path, "w") as f:

config/kube_config.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,8 @@ def set_active_context(self, context_name=None):
130130
context_name = self._config['current-context']
131131
self._current_context = self._config['contexts'].get_with_name(
132132
context_name)
133-
if (self._current_context['context'].safe_get('user')
134-
and self._config.safe_get('users')):
133+
if (self._current_context['context'].safe_get('user') and
134+
self._config.safe_get('users')):
135135
user = self._config['users'].get_with_name(
136136
self._current_context['context']['user'], safe=True)
137137
if user:

configuration.py

+30-33
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,27 @@
1-
# coding: utf-8
2-
3-
"""
4-
Kubernetes
5-
6-
No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen)
7-
8-
OpenAPI spec version: v1.5.0-snapshot
9-
10-
Generated by: https://github.com/swagger-api/swagger-codegen.git
11-
12-
Licensed under the Apache License, Version 2.0 (the "License");
13-
you may not use this file except in compliance with the License.
14-
You may obtain a copy of the License at
15-
16-
http://www.apache.org/licenses/LICENSE-2.0
17-
18-
Unless required by applicable law or agreed to in writing, software
19-
distributed under the License is distributed on an "AS IS" BASIS,
20-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21-
See the License for the specific language governing permissions and
22-
limitations under the License.
23-
"""
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.
2418

2519
from __future__ import absolute_import
2620

27-
import urllib3
28-
29-
import sys
3021
import logging
22+
import sys
3123

24+
import urllib3
3225
from six import iteritems
3326
from six.moves import http_client as httplib
3427

@@ -77,7 +70,8 @@ def __init__(self):
7770
self.debug = False
7871

7972
# SSL/TLS verification
80-
# Set this to false to skip verifying SSL certificate when calling API from https server.
73+
# Set this to false to skip verifying SSL certificate when calling API
74+
# from https server.
8175
self.verify_ssl = True
8276
# Set this to customize the certificate file to verify the peer.
8377
self.ssl_ca_cert = None
@@ -101,8 +95,8 @@ def logger_file(self, value):
10195
"""
10296
Sets the logger_file.
10397
104-
If the logger_file is None, then add stream handler and remove file handler.
105-
Otherwise, add file handler and remove stream handler.
98+
If the logger_file is None, then add stream handler and remove file
99+
handler. Otherwise, add file handler and remove stream handler.
106100
107101
:param value: The logger_file path.
108102
:type: str
@@ -184,8 +178,10 @@ def get_api_key_with_prefix(self, identifier):
184178
:param identifier: The identifier of apiKey.
185179
:return: The token for api key authentication.
186180
"""
187-
if self.api_key.get(identifier) and self.api_key_prefix.get(identifier):
188-
return self.api_key_prefix[identifier] + ' ' + self.api_key[identifier]
181+
if (self.api_key.get(identifier) and
182+
self.api_key_prefix.get(identifier)):
183+
return (self.api_key_prefix[identifier] + ' ' +
184+
self.api_key[identifier])
189185
elif self.api_key.get(identifier):
190186
return self.api_key[identifier]
191187

@@ -195,8 +191,9 @@ def get_basic_auth_token(self):
195191
196192
:return: The token for basic HTTP authentication.
197193
"""
198-
return urllib3.util.make_headers(basic_auth=self.username + ':' + self.password)\
199-
.get('authorization')
194+
return urllib3.util.make_headers(
195+
basic_auth=self.username + ':' + self.password).get(
196+
'authorization')
200197

201198
def auth_settings(self):
202199
"""

0 commit comments

Comments
 (0)