summaryrefslogtreecommitdiff
path: root/requests_cache
diff options
context:
space:
mode:
authorJordan Cook <jordan.cook@pioneer.com>2022-01-01 12:02:10 -0600
committerJordan Cook <jordan.cook@pioneer.com>2022-01-01 12:10:43 -0600
commit023b9bf36a4305f5edceece7ac6eabbd16e2e40d (patch)
treeb9238fb788560d94b2602c8996873750c5273abb /requests_cache
parent347048289ed25ec847a40dc5971ee8a538b4aebf (diff)
downloadrequests-cache-023b9bf36a4305f5edceece7ac6eabbd16e2e40d.tar.gz
Format using a more typical line length of 100
Diffstat (limited to 'requests_cache')
-rw-r--r--requests_cache/backends/dynamodb.py8
-rw-r--r--requests_cache/cache_keys.py8
-rwxr-xr-xrequests_cache/models/response.py5
-rw-r--r--requests_cache/serializers/cattrs.py4
-rw-r--r--requests_cache/serializers/preconf.py8
-rw-r--r--requests_cache/session.py16
6 files changed, 38 insertions, 11 deletions
diff --git a/requests_cache/backends/dynamodb.py b/requests_cache/backends/dynamodb.py
index e1a6089..689b43f 100644
--- a/requests_cache/backends/dynamodb.py
+++ b/requests_cache/backends/dynamodb.py
@@ -64,7 +64,9 @@ class DynamoDbCache(BaseCache):
kwargs: Additional keyword arguments for :py:meth:`~boto3.session.Session.resource`
"""
- def __init__(self, table_name: str = 'http_cache', connection: ServiceResource = None, **kwargs):
+ def __init__(
+ self, table_name: str = 'http_cache', connection: ServiceResource = None, **kwargs
+ ):
super().__init__(**kwargs)
self.responses = DynamoDbDict(table_name, 'responses', connection=connection, **kwargs)
self.redirects = DynamoDbDict(
@@ -148,7 +150,9 @@ class DynamoDbDict(BaseStorage):
# Depending on the serializer, the value may be either a string or Binary object
raw_value = result['Item']['value']
- return self.serializer.loads(raw_value.value if isinstance(raw_value, Binary) else raw_value)
+ return self.serializer.loads(
+ raw_value.value if isinstance(raw_value, Binary) else raw_value
+ )
def __setitem__(self, key, value):
item = {**self.composite_key(key), 'value': self.serializer.dumps(value)}
diff --git a/requests_cache/cache_keys.py b/requests_cache/cache_keys.py
index 7029c7f..5b86a1a 100644
--- a/requests_cache/cache_keys.py
+++ b/requests_cache/cache_keys.py
@@ -82,7 +82,9 @@ def get_matched_headers(
included = set(headers) - DEFAULT_EXCLUDE_HEADERS
return [
- f'{k.lower()}={headers[k]}' for k in sorted(included, key=lambda x: x.lower()) if k in headers
+ f'{k.lower()}={headers[k]}'
+ for k in sorted(included, key=lambda x: x.lower())
+ if k in headers
]
@@ -110,7 +112,9 @@ def normalize_request(request: AnyRequest, ignored_parameters: ParamList) -> Any
return norm_request
-def normalize_headers(headers: Mapping[str, str], ignored_parameters: ParamList) -> CaseInsensitiveDict:
+def normalize_headers(
+ headers: Mapping[str, str], ignored_parameters: ParamList
+) -> CaseInsensitiveDict:
"""Sort and filter request headers"""
if ignored_parameters:
headers = filter_sort_dict(headers, ignored_parameters)
diff --git a/requests_cache/models/response.py b/requests_cache/models/response.py
index 561d6c8..73b09fd 100755
--- a/requests_cache/models/response.py
+++ b/requests_cache/models/response.py
@@ -48,7 +48,10 @@ class CachedResponse(Response):
@classmethod
def from_response(
- cls, original_response: Union[Response, 'CachedResponse'], expires: datetime = None, **kwargs
+ cls,
+ original_response: Union[Response, 'CachedResponse'],
+ expires: datetime = None,
+ **kwargs,
):
"""Create a CachedResponse based on an original Response or another CachedResponse object"""
if isinstance(original_response, CachedResponse):
diff --git a/requests_cache/serializers/cattrs.py b/requests_cache/serializers/cattrs.py
index b28acd0..7b483d7 100644
--- a/requests_cache/serializers/cattrs.py
+++ b/requests_cache/serializers/cattrs.py
@@ -59,7 +59,9 @@ def init_converter(factory: Callable[..., GenConverter] = None):
converter.register_unstructure_hook(RequestsCookieJar, lambda obj: dict(obj.items())) # type: ignore
converter.register_structure_hook(RequestsCookieJar, lambda obj, cls: cookiejar_from_dict(obj))
converter.register_unstructure_hook(CaseInsensitiveDict, dict)
- converter.register_structure_hook(CaseInsensitiveDict, lambda obj, cls: CaseInsensitiveDict(obj))
+ converter.register_structure_hook(
+ CaseInsensitiveDict, lambda obj, cls: CaseInsensitiveDict(obj)
+ )
converter.register_unstructure_hook(HTTPHeaderDict, dict)
converter.register_structure_hook(HTTPHeaderDict, lambda obj, cls: HTTPHeaderDict(obj))
diff --git a/requests_cache/serializers/preconf.py b/requests_cache/serializers/preconf.py
index dce7e60..67d1453 100644
--- a/requests_cache/serializers/preconf.py
+++ b/requests_cache/serializers/preconf.py
@@ -23,7 +23,9 @@ from .._utils import get_placeholder_class
from .cattrs import CattrStage
from .pipeline import SerializerPipeline, Stage
-base_stage = CattrStage() #: Base stage for all serializer pipelines (or standalone dict serializer)
+base_stage = (
+ CattrStage()
+) #: Base stage for all serializer pipelines (or standalone dict serializer)
dict_serializer = base_stage #: Partial serializer that unstructures responses into dicts
bson_preconf_stage = CattrStage(bson_preconf.make_converter) #: Pre-serialization steps for BSON
json_preconf_stage = CattrStage(json_preconf.make_converter) #: Pre-serialization steps for JSON
@@ -47,7 +49,9 @@ try:
"""
return Stage(Signer(secret_key=secret_key, salt=salt), dumps='sign', loads='unsign')
- def safe_pickle_serializer(secret_key=None, salt='requests-cache', **kwargs) -> SerializerPipeline:
+ def safe_pickle_serializer(
+ secret_key=None, salt='requests-cache', **kwargs
+ ) -> SerializerPipeline:
"""Create a serializer that uses ``pickle`` + ``itsdangerous`` to add a signature to
responses on write, and validate that signature with a secret key on read.
"""
diff --git a/requests_cache/session.py b/requests_cache/session.py
index 578e7c8..26c06e5 100644
--- a/requests_cache/session.py
+++ b/requests_cache/session.py
@@ -198,7 +198,11 @@ class CacheMixin(MIXIN_BASE):
return set_response_defaults(response, actions.cache_key)
def _resend(
- self, request: PreparedRequest, actions: CacheActions, cached_response: CachedResponse, **kwargs
+ self,
+ request: PreparedRequest,
+ actions: CacheActions,
+ cached_response: CachedResponse,
+ **kwargs,
) -> AnyResponse:
"""Attempt to resend the request and cache the new response. If the request fails, delete
the stale cache item.
@@ -211,7 +215,11 @@ class CacheMixin(MIXIN_BASE):
raise
def _resend_and_ignore(
- self, request: PreparedRequest, actions: CacheActions, cached_response: CachedResponse, **kwargs
+ self,
+ request: PreparedRequest,
+ actions: CacheActions,
+ cached_response: CachedResponse,
+ **kwargs,
) -> AnyResponse:
"""Attempt to resend the request and cache the new response. If there are any errors, ignore
them and and return the stale cache item.
@@ -223,7 +231,9 @@ class CacheMixin(MIXIN_BASE):
response.raise_for_status()
return response
except Exception:
- logger.warning(f'Request for URL {request.url} failed; using cached response', exc_info=True)
+ logger.warning(
+ f'Request for URL {request.url} failed; using cached response', exc_info=True
+ )
return cached_response
def _update_revalidated_response(