66
77import requests
88import requests .adapters
9+ from urllib3 .util import Retry
910
1011DEFAULT_RETRIES_TOTAL = 5
1112
2829)
2930
3031
31- def retry_adapter (
32+ def retry_configuration (
3233 * ,
3334 total : int = DEFAULT_RETRIES_TOTAL ,
3435 backoff_factor : float = DEFAULT_BACKOFF_FACTOR ,
3536 status_forcelist : Collection [int ] = DEFAULT_RETRY_FORCELIST ,
3637 ** kwargs ,
37- ) -> requests . adapters . Retry :
38+ ) -> Retry :
3839 """
39- Factory for creating a `requests.adapters .Retry` configuration object with
40+ Factory for creating a :py:class:`urllib3.util.retry .Retry` configuration object with
4041 openEO-oriented retry settings.
4142
4243 :param total: Total number of retries to allow
4344 :param backoff_factor: scaling factor for sleeps between retries
4445 :param status_forcelist: A set of integer HTTP status codes that we should force a retry on.
45- :param kwargs: additional kwargs to pass to `requests.adapters .Retry`
46+ :param kwargs: additional kwargs to pass to :py:class:`urllib3.util.retry .Retry`
4647 :return:
4748
4849 Inspiration and references:
4950 - https://requests.readthedocs.io/en/latest/api/#requests.adapters.HTTPAdapter
5051 - https://urllib3.readthedocs.io/en/latest/reference/urllib3.util.html#urllib3.util.Retry
5152 - https://findwork.dev/blog/advanced-usage-python-requests-timeouts-retries-hooks/#retry-on-failure
5253 """
53- retry = requests . adapters . Retry (
54+ retry = Retry (
5455 total = total ,
5556 backoff_factor = backoff_factor ,
5657 status_forcelist = status_forcelist ,
@@ -59,32 +60,28 @@ def retry_adapter(
5960 return retry
6061
6162
62- def _to_retry (
63- retry : Union [requests .adapters .Retry , dict , None ],
64- ) -> requests .adapters .Retry :
63+ def _to_retry (retry : Union [Retry , dict , None ]) -> Retry :
6564 """
66- Convert a retry specification to a `requests.adapters .Retry` object.
65+ Convert a retry specification to a :py:class:`urllib3.util.retry .Retry` object.
6766 """
68- if isinstance (retry , requests . adapters . Retry ):
69- return retry
67+ if isinstance (retry , Retry ):
68+ pass
7069 elif isinstance (retry , dict ):
71- adapter = retry_adapter (** retry )
70+ retry = retry_configuration (** retry )
7271 elif retry in {None , True }:
73- adapter = retry_adapter ()
72+ retry = retry_configuration ()
7473 else :
7574 raise ValueError (f"Invalid retry setting: { retry !r} " )
76- return adapter
75+ return retry
7776
7877
79- def session_with_retries (
80- retry : Union [requests .adapters .Retry , dict , None ] = None ,
81- ) -> requests .Session :
78+ def session_with_retries (retry : Union [Retry , dict , None ] = None ) -> requests .Session :
8279 """
8380 Factory for a requests session with openEO-oriented retry settings.
8481
8582 :param retry: The retry configuration, can be specified as:
86- - :py:class:`requests.adapters .Retry`
87- - a dictionary with :py:class:`requests.adapters .Retry` arguments,
83+ - :py:class:`urllib3.util.retry .Retry`
84+ - a dictionary with :py:class:`urllib3.util.retry .Retry` arguments,
8885 e.g. ``total``, ``backoff_factor``, ``status_forcelist``, ...
8986 - ``None`` for default openEO-oriented retry settings
9087 """
0 commit comments