Skip to content

Commit

Permalink
Formatting updates after running black
Browse files Browse the repository at this point in the history
  • Loading branch information
ionrock committed Oct 31, 2021
1 parent 6661c3b commit 09992a1
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions cachecontrol/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ def cached_request(self, request):
# with cache busting headers as usual (ie no-cache).
if int(resp.status) in PERMANENT_REDIRECT_STATUSES:
msg = (
'Returning cached permanent redirect response '
"Returning cached permanent redirect response "
"(ignoring date and etag information)"
)
logger.debug(msg)
Expand Down Expand Up @@ -268,10 +268,8 @@ def cache_response(self, request, response, body=None, status_codes=None):

response_headers = CaseInsensitiveDict(response.headers)

if 'date' in response_headers:
date = calendar.timegm(
parsedate_tz(response_headers['date'])
)
if "date" in response_headers:
date = calendar.timegm(parsedate_tz(response_headers["date"]))
else:
date = 0

Expand Down Expand Up @@ -319,55 +317,57 @@ def cache_response(self, request, response, body=None, status_codes=None):
# If we've been given an etag, then keep the response
if self.cache_etags and "etag" in response_headers:
expires_time = 0
if response_headers.get('expires'):
expires = parsedate_tz(response_headers['expires'])
if response_headers.get("expires"):
expires = parsedate_tz(response_headers["expires"])
if expires is not None:
expires_time = calendar.timegm(expires) - date

expires_time = max(expires_time, 14 * 86400)

logger.debug('etag object cached for {0} seconds'.format(expires_time))
logger.debug("etag object cached for {0} seconds".format(expires_time))
logger.debug("Caching due to etag")
self.cache.set(
cache_url,
self.serializer.dumps(request, response, body),
expires=expires_time
expires=expires_time,
)

# Add to the cache any permanent redirects. We do this before looking
# that the Date headers.
elif int(response.status) in PERMANENT_REDIRECT_STATUSES:
logger.debug("Caching permanent redirect")
self.cache.set(cache_url, self.serializer.dumps(request, response, b''))
self.cache.set(cache_url, self.serializer.dumps(request, response, b""))

# Add to the cache if the response headers demand it. If there
# is no date header then we can't do anything about expiring
# the cache.
elif "date" in response_headers:
date = calendar.timegm(
parsedate_tz(response_headers['date'])
)
date = calendar.timegm(parsedate_tz(response_headers["date"]))
# cache when there is a max-age > 0
if "max-age" in cc and cc["max-age"] > 0:
logger.debug("Caching b/c date exists and max-age > 0")
expires_time = cc['max-age']
expires_time = cc["max-age"]
self.cache.set(
cache_url,
self.serializer.dumps(request, response, body),
expires=expires_time
expires=expires_time,
)

# If the request can expire, it means we should cache it
# in the meantime.
elif "expires" in response_headers:
if response_headers["expires"]:
expires = parsedate_tz(response_headers['expires'])
expires = parsedate_tz(response_headers["expires"])
if expires is not None:
expires_time = calendar.timegm(expires) - date
else:
expires_time = None

logger.debug('Caching b/c of expires header. expires in {0} seconds'.format(expires_time))
logger.debug(
"Caching b/c of expires header. expires in {0} seconds".format(
expires_time
)
)
self.cache.set(
cache_url,
self.serializer.dumps(request, response, body=body),
Expand Down

0 comments on commit 09992a1

Please sign in to comment.