summaryrefslogtreecommitdiff
path: root/src/pip/_vendor/tenacity/retry.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/pip/_vendor/tenacity/retry.py')
-rw-r--r--src/pip/_vendor/tenacity/retry.py27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/pip/_vendor/tenacity/retry.py b/src/pip/_vendor/tenacity/retry.py
index 1d727e9b3..9ebeb62d5 100644
--- a/src/pip/_vendor/tenacity/retry.py
+++ b/src/pip/_vendor/tenacity/retry.py
@@ -117,6 +117,33 @@ class retry_unless_exception_type(retry_if_exception):
return self.predicate(retry_state.outcome.exception())
+class retry_if_exception_cause_type(retry_base):
+ """Retries if any of the causes of the raised exception is of one or more types.
+
+ The check on the type of the cause of the exception is done recursively (until finding
+ an exception in the chain that has no `__cause__`)
+ """
+
+ def __init__(
+ self,
+ exception_types: typing.Union[
+ typing.Type[BaseException],
+ typing.Tuple[typing.Type[BaseException], ...],
+ ] = Exception,
+ ) -> None:
+ self.exception_cause_types = exception_types
+
+ def __call__(self, retry_state: "RetryCallState") -> bool:
+ if retry_state.outcome.failed:
+ exc = retry_state.outcome.exception()
+ while exc is not None:
+ if isinstance(exc.__cause__, self.exception_cause_types):
+ return True
+ exc = exc.__cause__
+
+ return False
+
+
class retry_if_result(retry_base):
"""Retries if the result verifies a predicate."""