Skip to content

Commit 81ca118

Browse files
committed
Apply new black formatting
Signed-off-by: George Melikov <mail@gmelikov.ru>
1 parent 3926f23 commit 81ca118

19 files changed

Lines changed: 356 additions & 278 deletions

File tree

httpetcd/base/client.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,9 @@ class HTTPEtcdClient(obj.BaseObject):
3030
def __init__(self, conf):
3131
super(HTTPEtcdClient, self).__init__()
3232
self._conf = conf
33-
self._s = session.get_session(endpoints=conf.endpoints,
34-
timeout=conf.timeout)
33+
self._s = session.get_session(
34+
endpoints=conf.endpoints, timeout=conf.timeout
35+
)
3536

3637
@property
3738
def conf(self):

httpetcd/clients.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,17 @@
2525

2626
class Config(obj.BaseObject):
2727

28-
_NS_REGEXP_STR = '^[a-z0-9._-]+$'
28+
_NS_REGEXP_STR = "^[a-z0-9._-]+$"
2929
_NS_REGEXP = re.compile(_NS_REGEXP_STR, re.IGNORECASE)
3030

3131
def __init__(self, endpoints, namespace, timeout):
3232
super(Config, self).__init__()
3333
self._endpoints = endpoints
3434
if not self._NS_REGEXP.match(namespace):
35-
raise ValueError("Namespace %r does not match %r"
36-
% (namespace, self._NS_REGEXP_STR))
35+
raise ValueError(
36+
"Namespace %r does not match %r"
37+
% (namespace, self._NS_REGEXP_STR)
38+
)
3739
self._namespace = namespace
3840
self._timeout = timeout
3941

@@ -51,14 +53,14 @@ def timeout(self):
5153

5254

5355
def _get_client(client_cls, endpoints, namespace, timeout):
54-
conf = Config(endpoints=endpoints,
55-
namespace=namespace,
56-
timeout=timeout)
56+
conf = Config(endpoints=endpoints, namespace=namespace, timeout=timeout)
5757
return client_cls(conf=conf)
5858

5959

6060
def get_wrapped_client(endpoints, namespace, timeout):
61-
return _get_client(client_cls=wrapped_client.WrappedHTTPEtcdClient,
62-
endpoints=endpoints,
63-
namespace=namespace,
64-
timeout=timeout)
61+
return _get_client(
62+
client_cls=wrapped_client.WrappedHTTPEtcdClient,
63+
endpoints=endpoints,
64+
namespace=namespace,
65+
timeout=timeout,
66+
)

httpetcd/common/exc.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,9 @@ def suppress_any(msg=None, level=logging.ERROR, exc_info=True, adapter=None):
3737

3838

3939
@contextlib.contextmanager
40-
def reraise_original(msg=None, level=logging.ERROR, exc_info=True,
41-
adapter=None):
40+
def reraise_original(
41+
msg=None, level=logging.ERROR, exc_info=True, adapter=None
42+
):
4243
_exc_info = sys.exc_info()
4344
try:
4445
yield

httpetcd/exceptions.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,5 +59,6 @@ class UnsuccessfulResponse(EtcdException):
5959
def __init__(self, code, resp):
6060
self.code = code
6161
self.resp = resp
62-
super(UnsuccessfulResponse, self).__init__("Server returned code: %s"
63-
% self.code)
62+
super(UnsuccessfulResponse, self).__init__(
63+
"Server returned code: %s" % self.code
64+
)

httpetcd/library/session.py

Lines changed: 39 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -55,39 +55,52 @@ def __init__(self, endpoints, api_path, timeout):
5555
def _shift_endpoint(self, reason):
5656
old_ep = self._endpoint
5757
self._endpoint = next(self._ep_cycled)
58-
self._l(LOG).info("Shifted endpoint from %s to %s for reason: %r",
59-
old_ep, self._endpoint, reason)
58+
self._l(LOG).info(
59+
"Shifted endpoint from %s to %s for reason: %r",
60+
old_ep,
61+
self._endpoint,
62+
reason,
63+
)
6064

6165
def request(self, path, data, codes=enum.IntEnum):
6266
url = compat.urljoin(self._endpoint, path)
6367
try:
64-
self._l(LOG).debug("Requesting url %s with timeout %d",
65-
url, self._timeout)
66-
resp = self._session.post(url=url,
67-
json=data,
68-
timeout=self._timeout)
68+
self._l(LOG).debug(
69+
"Requesting url %s with timeout %d", url, self._timeout
70+
)
71+
resp = self._session.post(
72+
url=url, json=data, timeout=self._timeout
73+
)
6974
except req_exc.ConnectionError as e:
7075
self._shift_endpoint(e)
7176
exc_info = sys.exc_info()
72-
six.reraise(exceptions.ConnectionError,
73-
exceptions.ConnectionError((self._endpoint,),
74-
repr(exc_info[1])),
75-
exc_info[2])
77+
six.reraise(
78+
exceptions.ConnectionError,
79+
exceptions.ConnectionError(
80+
(self._endpoint,), repr(exc_info[1])
81+
),
82+
exc_info[2],
83+
)
7684
except req_exc.ReadTimeout:
7785
# May happen when master etcd node location is controlled by
7886
# switching IP address in DNS record pointing to the master node.
7987
# We have to reestablish connection to fetch correct IP address.
8088
self._session.close()
8189
exc_info = sys.exc_info()
82-
six.reraise(exceptions.ConnectionError,
83-
exceptions.ConnectionError((self._endpoint,),
84-
repr(exc_info[1])),
85-
exc_info[2])
90+
six.reraise(
91+
exceptions.ConnectionError,
92+
exceptions.ConnectionError(
93+
(self._endpoint,), repr(exc_info[1])
94+
),
95+
exc_info[2],
96+
)
8697
except Exception:
8798
exc_info = sys.exc_info()
88-
six.reraise(exceptions.EtcdException,
89-
exceptions.EtcdException(repr(exc_info[1])),
90-
exc_info[2])
99+
six.reraise(
100+
exceptions.EtcdException,
101+
exceptions.EtcdException(repr(exc_info[1])),
102+
exc_info[2],
103+
)
91104
resp.raise_for_status()
92105
result = resp.json()
93106
self._l(LOG).debug("Response: %s", result)
@@ -98,13 +111,16 @@ def request(self, path, data, codes=enum.IntEnum):
98111
try:
99112
code = codes(result["code"])
100113
except ValueError:
101-
raise exceptions.UnknownResponseCode("path=%s, data=%r, result=%r"
102-
% (path, data, result))
114+
raise exceptions.UnknownResponseCode(
115+
"path=%s, data=%r, result=%r" % (path, data, result)
116+
)
103117

104118
raise exceptions.UnsuccessfulResponse(code=code, resp=result)
105119

106120

107121
def get_session(endpoints, timeout):
108-
return Session(endpoints=endpoints,
109-
api_path=constants.APIVersions.V3BETA.value + "/",
110-
timeout=timeout)
122+
return Session(
123+
endpoints=endpoints,
124+
api_path=constants.APIVersions.V3BETA.value + "/",
125+
timeout=timeout,
126+
)

httpetcd/raw/entities/lease.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,9 @@ def id(self):
4646

4747
def refresh(self):
4848
self._l(LOG).debug("Refreshing...")
49-
resp = self._session.request(path="lease/keepalive",
50-
data={"ID": self._id})
49+
resp = self._session.request(
50+
path="lease/keepalive", data={"ID": self._id}
51+
)
5152

5253
try:
5354
result = resp["result"]
@@ -62,9 +63,9 @@ def refresh(self):
6263
raise exceptions.LeaseExpired()
6364

6465
def _ttl(self, with_keys):
65-
return self._session.request(path="lease/timetolive",
66-
data={"ID": self._id,
67-
"keys": with_keys})
66+
return self._session.request(
67+
path="lease/timetolive", data={"ID": self._id, "keys": with_keys}
68+
)
6869

6970
def ttl(self):
7071
resp = self._ttl(with_keys=False)
@@ -97,9 +98,9 @@ def revoke(self):
9798
self._l(LOG).debug("Revoking...")
9899
lr_codes = codes.LeaseRevokeCodes
99100
try:
100-
self._session.request(path="lease/revoke",
101-
data={"ID": self._id},
102-
codes=lr_codes)
101+
self._session.request(
102+
path="lease/revoke", data={"ID": self._id}, codes=lr_codes
103+
)
103104
self._l(LOG).info("Revoked.")
104105
return True
105106
except exceptions.UnsuccessfulResponse as e:

0 commit comments

Comments
 (0)