Skip to content

Commit 7fc47b0

Browse files
committed
Fix formatting
1 parent 6155efe commit 7fc47b0

File tree

2 files changed

+30
-19
lines changed

2 files changed

+30
-19
lines changed

fastpurge/_client.py

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626

2727
LOG = logging.getLogger('fastpurge')
2828

29-
3029
Purge = namedtuple('Purge', [
3130
# Response from Akamai when this purge was created
3231
'response_body',
@@ -50,14 +49,16 @@ def increment(self, method, url, *args, **kwargs):
5049
if response:
5150
self._logger.error("An invalid status code %s was received "
5251
"when trying to %s to %s: %s"
53-
% (response.status, method, url, response.reason))
52+
% (
53+
response.status, method, url, response.reason))
5454
else:
5555
self._logger.error(
5656
"An unknown error occurred when trying to %s to %s"
5757
% (method, url))
5858
return super(LoggingRetry, self).increment(method, url, *args,
5959
**kwargs)
6060

61+
6162
class FastPurgeError(RuntimeError):
6263
"""Raised when the Fast Purge API reports an error.
6364
@@ -98,7 +99,8 @@ class FastPurgeClient(object):
9899
MAX_REQUESTS = int(os.environ.get("FAST_PURGE_MAX_REQUESTS", "10"))
99100

100101
# Default network matches Akamai's documented default
101-
DEFAULT_NETWORK = os.environ.get("FAST_PURGE_DEFAULT_NETWORK", "production")
102+
DEFAULT_NETWORK = os.environ.get("FAST_PURGE_DEFAULT_NETWORK",
103+
"production")
102104

103105
# Max number of retries allowed for HTTP requests, and the backoff used
104106
# to extend the delay between requests.
@@ -168,11 +170,11 @@ def __executor(self):
168170
if self.___executor is None:
169171
with self.__lock:
170172
if self.___executor is None:
171-
self.___executor = Executors.\
172-
sync(name="fastpurge").\
173-
with_poll(self.__poll_purges).\
174-
with_throttle(count=self.MAX_REQUESTS).\
175-
with_retry().\
173+
self.___executor = Executors. \
174+
sync(name="fastpurge"). \
175+
with_poll(self.__poll_purges). \
176+
with_throttle(count=self.MAX_REQUESTS). \
177+
with_retry(). \
176178
with_cancel_on_shutdown()
177179
return self.___executor
178180

@@ -189,7 +191,8 @@ def __poll_purges(cls, descriptors):
189191
earliest = now + cls.DEFAULT_DELAY
190192

191193
for descriptor in descriptors:
192-
purge_id = descriptor.result.response_body.get('purgeId', '<unknown purge>')
194+
purge_id = descriptor.result.response_body.get('purgeId',
195+
'<unknown purge>')
193196
when_complete = descriptor.result.estimated_complete
194197
earliest = min(earliest, when_complete)
195198
if when_complete > now:
@@ -212,7 +215,8 @@ def __poll_purges(cls, descriptors):
212215
# here.
213216
descriptor.yield_result(descriptor.result.response_body)
214217

215-
LOG.debug("now %s, earliest %s, sleep %s", now, earliest, earliest - now)
218+
LOG.debug("now %s, earliest %s, sleep %s", now, earliest,
219+
earliest - now)
216220
return min(earliest - now, cls.DEFAULT_DELAY)
217221

218222
@property
@@ -267,25 +271,27 @@ def __get_request_bodies(self, objects):
267271

268272
# Too big for a single request.
269273
# Split it in half and try again
270-
part = int(len(objects)/2)
274+
part = int(len(objects) / 2)
271275
objects_a, objects_b = objects[:part], objects[part:]
272-
return self.__get_request_bodies(objects_a) + self.__get_request_bodies(objects_b)
276+
return self.__get_request_bodies(
277+
objects_a) + self.__get_request_bodies(objects_b)
273278

274279
def __start_purge(self, endpoint, request_body):
275280
headers = {'Content-Type': 'application/json'}
276281
LOG.debug("POST JSON of size %s to %s", len(request_body), endpoint)
277282
try:
278-
response = self.__session.post(endpoint, data=request_body, headers=headers)
283+
response = self.__session.post(endpoint, data=request_body,
284+
headers=headers)
279285
response_body = response.json()
280286
estimated_seconds = response_body.get('estimatedSeconds', 5)
281287
return Purge(response_body, monotonic() + estimated_seconds)
282288
except RetryError as e:
283289
message = "Request to {endpoint} was unsuccessful after {retries} retries: {reason}". \
284-
format(endpoint=endpoint, retries=self.MAX_RETRIES, reason=e.args[0].reason)
290+
format(endpoint=endpoint, retries=self.MAX_RETRIES,
291+
reason=e.args[0].reason)
285292
LOG.debug(message)
286293
raise FastPurgeError(message)
287294

288-
289295
def purge_objects(self, object_type, objects, **kwargs):
290296
"""Purge a collection of objects.
291297
@@ -348,7 +354,8 @@ def purge_objects(self, object_type, objects, **kwargs):
348354

349355
futures = []
350356
for request_body in request_bodies:
351-
future = self.__executor.submit(self.__start_purge, endpoint, request_body)
357+
future = self.__executor.submit(self.__start_purge, endpoint,
358+
request_body)
352359
futures.append(future)
353360

354361
return f_sequence(futures)

tests/test_purge.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
from fastpurge import FastPurgeClient, FastPurgeError
1313

14+
1415
# pylint: disable=unused-argument
1516

1617

@@ -42,7 +43,8 @@ def requests_mocker():
4243
def no_thread_retries():
4344
"""Suppress retries for the duration of this fixture."""
4445

45-
with mock.patch('more_executors.retry.ExceptionRetryPolicy') as policy_class:
46+
with mock.patch(
47+
'more_executors.retry.ExceptionRetryPolicy') as policy_class:
4648
policy = policy_class.return_value
4749
policy.should_retry.return_value = False
4850
policy.sleep_time.return_value = 0.1
@@ -105,7 +107,8 @@ def test_purge_by_tag(client, requests_mocker):
105107
status_code=201,
106108
json=response)
107109

108-
future = client.purge_by_tag(["red", "blue", "green"], purge_type='invalidate')
110+
future = client.purge_by_tag(["red", "blue", "green"],
111+
purge_type='invalidate')
109112

110113
# It should have succeeded
111114
assert future.result()
@@ -134,7 +137,7 @@ def test_scheme_port(client_auth, requests_mocker):
134137

135138

136139
@responses.activate
137-
def test_response_fails(client, no_thread_retries):
140+
def test_response_fails(client, no_thread_retries):
138141
"""Requests fail with a FastPurgeError if API gives unsuccessful response."""
139142
url = 'https://fastpurge.example.com/ccu/v3/delete/cpcode/production'
140143
# Decrease backoff, otherwise the test will run for 5 minutes
@@ -203,6 +206,7 @@ def test_multiple_clients_with_the_same_auth_dict(client_auth):
203206

204207
assert client1 is not client2
205208

209+
206210
@responses.activate(registry=responses.registries.OrderedRegistry)
207211
def test_retries_on_error(client_auth):
208212
"""Sanity check for the retry functionality"""

0 commit comments

Comments
 (0)