Skip to content

Commit 0a5b04f

Browse files
committed
Revert black and only try autopep8 this time
1 parent 34b8304 commit 0a5b04f

File tree

2 files changed

+33
-49
lines changed

2 files changed

+33
-49
lines changed

config/__init__.py

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,8 @@
1515
import os
1616
from .config_exception import ConfigException
1717
from .incluster_config import load_incluster_config
18-
from .kube_config import (
19-
list_kube_config_contexts,
20-
load_kube_config,
21-
load_kube_config_from_dict,
22-
new_client_from_config,
23-
KUBE_CONFIG_DEFAULT_LOCATION,
24-
)
18+
from .kube_config import (list_kube_config_contexts, load_kube_config,
19+
load_kube_config_from_dict, new_client_from_config, KUBE_CONFIG_DEFAULT_LOCATION)
2520

2621

2722
def load_config(**kwargs):
@@ -33,15 +28,9 @@ def load_config(**kwargs):
3328
:param kwargs: A combination of all possible kwargs that can be passed to either load_kube_config or
3429
load_incluster_config functions.
3530
"""
36-
if "kube_config_path" in kwargs.keys() or os.path.exists(
37-
KUBE_CONFIG_DEFAULT_LOCATION
38-
):
31+
if "kube_config_path" in kwargs.keys() or os.path.exists(KUBE_CONFIG_DEFAULT_LOCATION):
3932
load_kube_config(**kwargs)
4033
else:
41-
print(
42-
"kube_config_path not provided and default location ({0}) does not exist. "
43-
"Using inCluster Config. This might not work.".format(
44-
KUBE_CONFIG_DEFAULT_LOCATION
45-
)
46-
)
34+
print("kube_config_path not provided and default location ({0}) does not exist. "
35+
"Using inCluster Config. This might not work.".format(KUBE_CONFIG_DEFAULT_LOCATION))
4736
load_incluster_config(**kwargs)

watch/watch.py

Lines changed: 28 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,14 @@
3232
PY2 = sys.version_info[0] == 2
3333
if PY2:
3434
import httplib
35-
3635
HTTP_STATUS_GONE = httplib.GONE
3736
else:
3837
import http
39-
4038
HTTP_STATUS_GONE = http.HTTPStatus.GONE
4139

4240

4341
class SimpleNamespace:
42+
4443
def __init__(self, **kwargs):
4544
self.__dict__.update(kwargs)
4645

@@ -56,7 +55,7 @@ def iter_resp_lines(resp):
5655
prev = ""
5756
for seg in resp.read_chunked(decode_content=False):
5857
if isinstance(seg, bytes):
59-
seg = seg.decode("utf8")
58+
seg = seg.decode('utf8')
6059
seg = prev + seg
6160
lines = seg.split("\n")
6261
if not seg.endswith("\n"):
@@ -70,6 +69,7 @@ def iter_resp_lines(resp):
7069

7170

7271
class Watch(object):
72+
7373
def __init__(self, return_type=None):
7474
self._raw_return_type = return_type
7575
self._stop = False
@@ -84,31 +84,29 @@ def get_return_type(self, func):
8484
return self._raw_return_type
8585
return_type = _find_return_type(func)
8686
if return_type.endswith(TYPE_LIST_SUFFIX):
87-
return return_type[: -len(TYPE_LIST_SUFFIX)]
87+
return return_type[:-len(TYPE_LIST_SUFFIX)]
8888
return return_type
8989

9090
def get_watch_argument_name(self, func):
9191
if PYDOC_FOLLOW_PARAM in pydoc.getdoc(func):
92-
return "follow"
92+
return 'follow'
9393
else:
94-
return "watch"
94+
return 'watch'
9595

9696
def unmarshal_event(self, data, return_type):
9797
js = json.loads(data)
98-
js["raw_object"] = js["object"]
99-
if return_type and js["type"] != "ERROR":
100-
obj = SimpleNamespace(data=json.dumps(js["raw_object"]))
101-
js["object"] = self._api_client.deserialize(obj, return_type)
102-
if hasattr(js["object"], "metadata"):
103-
self.resource_version = js["object"].metadata.resource_version
98+
js['raw_object'] = js['object']
99+
if return_type and js['type'] != 'ERROR':
100+
obj = SimpleNamespace(data=json.dumps(js['raw_object']))
101+
js['object'] = self._api_client.deserialize(obj, return_type)
102+
if hasattr(js['object'], 'metadata'):
103+
self.resource_version = js['object'].metadata.resource_version
104104
# For custom objects that we don't have model defined, json
105105
# deserialization results in dictionary
106-
elif (
107-
isinstance(js["object"], dict)
108-
and "metadata" in js["object"]
109-
and "resourceVersion" in js["object"]["metadata"]
110-
):
111-
self.resource_version = js["object"]["metadata"]["resourceVersion"]
106+
elif (isinstance(js['object'], dict) and 'metadata' in js['object']
107+
and 'resourceVersion' in js['object']['metadata']):
108+
self.resource_version = js['object']['metadata'][
109+
'resourceVersion']
112110
return js
113111

114112
def stream(self, func, *args, **kwargs):
@@ -149,13 +147,13 @@ def stream(self, func, *args, **kwargs):
149147
return_type = self.get_return_type(func)
150148
watch_arg = self.get_watch_argument_name(func)
151149
kwargs[watch_arg] = True
152-
kwargs["_preload_content"] = False
153-
if "resource_version" in kwargs:
154-
self.resource_version = kwargs["resource_version"]
150+
kwargs['_preload_content'] = False
151+
if 'resource_version' in kwargs:
152+
self.resource_version = kwargs['resource_version']
155153

156154
# Do not attempt retries if user specifies a timeout.
157155
# We want to ensure we are returning within that timeout.
158-
disable_retries = "timeout_seconds" in kwargs
156+
disable_retries = ('timeout_seconds' in kwargs)
159157
retry_after_410 = False
160158
while True:
161159
resp = func(*args, **kwargs)
@@ -165,23 +163,20 @@ def stream(self, func, *args, **kwargs):
165163
# return raw string when we are streaming log
166164
if watch_arg == "watch":
167165
event = self.unmarshal_event(line, return_type)
168-
if isinstance(event, dict) and event["type"] == "ERROR":
169-
obj = event["raw_object"]
166+
if isinstance(event, dict) \
167+
and event['type'] == 'ERROR':
168+
obj = event['raw_object']
170169
# Current request expired, let's retry, (if enabled)
171170
# but only if we have not already retried.
172-
if (
173-
not disable_retries
174-
and not retry_after_410
175-
and obj["code"] == HTTP_STATUS_GONE
176-
):
171+
if not disable_retries and not retry_after_410 and \
172+
obj['code'] == HTTP_STATUS_GONE:
177173
retry_after_410 = True
178174
break
179175
else:
180176
reason = "%s: %s" % (
181-
obj["reason"], obj["message"])
177+
obj['reason'], obj['message'])
182178
raise client.rest.ApiException(
183-
status=obj["code"], reason=reason
184-
)
179+
status=obj['code'], reason=reason)
185180
else:
186181
retry_after_410 = False
187182
yield event
@@ -193,7 +188,7 @@ def stream(self, func, *args, **kwargs):
193188
resp.close()
194189
resp.release_conn()
195190
if self.resource_version is not None:
196-
kwargs["resource_version"] = self.resource_version
191+
kwargs['resource_version'] = self.resource_version
197192
else:
198193
self._stop = True
199194

0 commit comments

Comments
 (0)