diff options
author | Jordan Cook <jordan.cook@pioneer.com> | 2021-08-28 15:52:24 -0500 |
---|---|---|
committer | Jordan Cook <jordan.cook@pioneer.com> | 2021-08-28 15:52:26 -0500 |
commit | df5118ecbfb6b2333ab425884fffef40de13d97e (patch) | |
tree | c867076d18f5b3bb94945e0af722f1651ab323ef /requests_cache/__init__.py | |
parent | 60f4bb089c794ebc797cd016bbb9cd5ba5845ba0 (diff) | |
download | requests-cache-df5118ecbfb6b2333ab425884fffef40de13d97e.tar.gz |
Allow has_url(), delete_url(), and create_key() to optionally take requests.Request arguments
Diffstat (limited to 'requests_cache/__init__.py')
-rw-r--r-- | requests_cache/__init__.py | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/requests_cache/__init__.py b/requests_cache/__init__.py index 03c6a69..93e2033 100644 --- a/requests_cache/__init__.py +++ b/requests_cache/__init__.py @@ -1,5 +1,6 @@ # flake8: noqa: E402,F401 from logging import getLogger +from typing import Callable, Iterable, Dict logger = getLogger(__name__) @@ -31,9 +32,17 @@ def get_placeholder_class(original_exception: Exception = None): return Placeholder +def get_valid_kwargs(func: Callable, kwargs: Dict, extras: Iterable[str] = None) -> Dict: + """Get the subset of non-None ``kwargs`` that are valid params for ``func``""" + params = list(signature(func).parameters) + params.extend(extras or []) + return {k: v for k, v in kwargs.items() if k in params and v is not None} + + try: from .backends import * from .cache_control import DO_NOT_CACHE, CacheActions + from .cache_keys import create_key from .models import * from .patcher import * from .serializers import * |