Skip to content

Commit 0395a10

Browse files
committed
Run black linter to make update-pycodestyle happy
1 parent 9bce869 commit 0395a10

File tree

2 files changed

+50
-35
lines changed

2 files changed

+50
-35
lines changed

config/__init__.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,13 @@
1515
import os
1616
from .config_exception import ConfigException
1717
from .incluster_config import load_incluster_config
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)
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+
)
2025

2126

2227
def load_config(**kwargs):
@@ -28,9 +33,15 @@ def load_config(**kwargs):
2833
:param kwargs: A combination of all possible kwargs that can be passed to either load_kube_config or
2934
load_incluster_config functions.
3035
"""
31-
if "kube_config_path" in kwargs.keys() or os.path.exists(KUBE_CONFIG_DEFAULT_LOCATION):
36+
if "kube_config_path" in kwargs.keys() or os.path.exists(
37+
KUBE_CONFIG_DEFAULT_LOCATION
38+
):
3239
load_kube_config(**kwargs)
3340
else:
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))
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+
)
3647
load_incluster_config(**kwargs)

watch/watch.py

Lines changed: 34 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -32,30 +32,31 @@
3232
PY2 = sys.version_info[0] == 2
3333
if PY2:
3434
import httplib
35+
3536
HTTP_STATUS_GONE = httplib.GONE
3637
else:
3738
import http
39+
3840
HTTP_STATUS_GONE = http.HTTPStatus.GONE
3941

4042

4143
class SimpleNamespace:
42-
4344
def __init__(self, **kwargs):
4445
self.__dict__.update(kwargs)
4546

4647

4748
def _find_return_type(func):
4849
for line in pydoc.getdoc(func).splitlines():
4950
if line.startswith(PYDOC_RETURN_LABEL):
50-
return line[len(PYDOC_RETURN_LABEL):].strip()
51+
return line[len(PYDOC_RETURN_LABEL) :].strip()
5152
return ""
5253

5354

5455
def iter_resp_lines(resp):
5556
prev = ""
5657
for seg in resp.read_chunked(decode_content=False):
5758
if isinstance(seg, bytes):
58-
seg = seg.decode('utf8')
59+
seg = seg.decode("utf8")
5960
seg = prev + seg
6061
lines = seg.split("\n")
6162
if not seg.endswith("\n"):
@@ -69,7 +70,6 @@ def iter_resp_lines(resp):
6970

7071

7172
class Watch(object):
72-
7373
def __init__(self, return_type=None):
7474
self._raw_return_type = return_type
7575
self._stop = False
@@ -84,29 +84,31 @@ 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 (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']
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"]
110112
return js
111113

112114
def stream(self, func, *args, **kwargs):
@@ -147,13 +149,13 @@ def stream(self, func, *args, **kwargs):
147149
return_type = self.get_return_type(func)
148150
watch_arg = self.get_watch_argument_name(func)
149151
kwargs[watch_arg] = True
150-
kwargs['_preload_content'] = False
151-
if 'resource_version' in kwargs:
152-
self.resource_version = kwargs['resource_version']
152+
kwargs["_preload_content"] = False
153+
if "resource_version" in kwargs:
154+
self.resource_version = kwargs["resource_version"]
153155

154156
# Do not attempt retries if user specifies a timeout.
155157
# We want to ensure we are returning within that timeout.
156-
disable_retries = ('timeout_seconds' in kwargs)
158+
disable_retries = "timeout_seconds" in kwargs
157159
retry_after_410 = False
158160
while True:
159161
resp = func(*args, **kwargs)
@@ -163,20 +165,22 @@ def stream(self, func, *args, **kwargs):
163165
# return raw string when we are streaming log
164166
if watch_arg == "watch":
165167
event = self.unmarshal_event(line, return_type)
166-
if isinstance(event, dict) \
167-
and event['type'] == 'ERROR':
168-
obj = event['raw_object']
168+
if isinstance(event, dict) and event["type"] == "ERROR":
169+
obj = event["raw_object"]
169170
# Current request expired, let's retry, (if enabled)
170171
# but only if we have not already retried.
171-
if not disable_retries and not retry_after_410 and \
172-
obj['code'] == HTTP_STATUS_GONE:
172+
if (
173+
not disable_retries
174+
and not retry_after_410
175+
and obj["code"] == HTTP_STATUS_GONE
176+
):
173177
retry_after_410 = True
174178
break
175179
else:
176-
reason = "%s: %s" % (
177-
obj['reason'], obj['message'])
180+
reason = "%s: %s" % (obj["reason"], obj["message"])
178181
raise client.rest.ApiException(
179-
status=obj['code'], reason=reason)
182+
status=obj["code"], reason=reason
183+
)
180184
else:
181185
retry_after_410 = False
182186
yield event
@@ -188,7 +192,7 @@ def stream(self, func, *args, **kwargs):
188192
resp.close()
189193
resp.release_conn()
190194
if self.resource_version is not None:
191-
kwargs['resource_version'] = self.resource_version
195+
kwargs["resource_version"] = self.resource_version
192196
else:
193197
self._stop = True
194198

0 commit comments

Comments
 (0)