00000073
  A   ˆl–Ðz¾”ªe¶¥	@ŠãNÜlJbÑ¿�þ^k6Q9#lË Ê ?¿ƒ‚ÿÄ_ŠI|¥�+Wé3ž¯ÃÂ «    from asyncio import sleep
from typing import TYPE_CHECKING, Any, Awaitable, Callable, Tuple, Type, TypeVar

from redis.exceptions import ConnectionError, RedisError, TimeoutError

if TYPE_CHECKING:
    from redis.backoff import AbstractBackoff


T = TypeVar("T")


class Retry:
    """Retry a specific number of times after a failure"""

    __slots__ = "_backoff", "_retries", "_supported_errors"

    def __init__(
        self,
        backoff: "AbstractBackoff",
        retries: int,
        supported_errors: Tuple[Type[RedisError], ...] = (
            ConnectionError,
            TimeoutError,
        ),
    ):
        """
        Initialize a `Retry` object with a `Backoff` object
        that retries a maximum of `retries` times.
        `retries` can be negative to retry forever.
        You can specify the types of supported errors which trigger
        a retry with the `supported_errors` parameter.
        """
        self._backoff = backoff
        self._retries = retries
        self._supported_errors = supported_errors

    def update_supported_errors(self, specified_errors: list):
        """
        Updates the supported errors with the specified error types
        """
        self._supported_errors = tuple(
            set(self._supported_errors + tuple(specified_errors))
        )

    async def call_with_retry(
        self, do: Callable[[], Awaitable[T]], fail: Callable[[RedisError], Any]
    ) -> T:
        """
        Execute an operation that might fail and returns its result, or
        raise the exception that was thrown depending on the `Backoff` object.
        `do`: the operation to call. Expects no argument.
        `fail`: the failure handler, expects the last error that was thrown
        """
        self._backoff.reset()
        failures = 0
        while True:
            try:
                return await do()
            except self._supported_errors as error:
                failures += 1
                await fail(error)
                if self._retries >= 0 and failures > self._retries:
                    raise error
                backoff = self._backoff.compute(failures)
                if backoff > 0:
                    await sleep(backoff)
  W   ˆl–Ðz¾””ÜZÔ%�à[S�ÿ�þB'Y²¼ëíÇ+Cl€þÁƒiÐƒÆ_ˆI|¥�+y,a–Ým_JJi?u8 ¸ËW
˜´oÅ f    /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

/*
** File:          plgetopt.h
** Description:   utilities to parse argc/argv
*/

#if defined(PLGETOPT_H_)
#else
#define PLGETOPT_H_

#include "prtypes.h"

PR_BEGIN_EXTERN_C

typedef struct PLOptionInternal PLOptionInternal;

typedef enum
{
    PL_OPT_OK,              /* all's well with the option */
    PL_OPT_EOL,             /* end of options list */
    PL_OPT_BAD              /* invalid option (and value) */
} PLOptStatus;

typedef struct PLLongOpt
{
    const char * longOptName;   /* long option name string                  */
    PRIntn       longOption;    /* value put in PLOptState for this option. */
    PRBool       valueRequired; /* If option name not followed by '=',      */
    /* value is the next argument from argv.    */
} PLLongOpt;

typedef struct PLOptState
{
    char option;                /* the name of the option */
    const char *value;          /* the value of that option | NULL */

    PLOptionInternal *internal; /* private processing state */

    PRIntn   longOption;        /* value from PLLongOpt put here */
    PRIntn   longOptIndex;      /* index into caller's array of PLLongOpts */
} PLOptState;

/*
 * PL_CreateOptState
 *
 * The argument "options" points to a string of single-character option
 * names.  Option names that may have an option argument value must be
 * followed immediately by a ':' character.
 */
PR_EXTERN(PLOptState*) PL_Cr