o
    ÔèFh/  ã                   @   s”   d Z ddlZdZdZ	 ejjZ	 ejjZ	 dZ	 dZ		 ejjejj
ejjejjejjejjfZ	 G dd„ deƒZG d	d
„ d
eƒZG dd„ deƒZdS )zŠCommon utilities for Google Media Downloads and Resumable Uploads.

Includes custom exception types, useful constants and shared helpers.
é    NzIAt most one of `max_cumulative_retry` and `max_retries` can be specified.i   g      P@g     À‚@c                       ó    e Zd ZdZ‡ fdd„Z‡  ZS )ÚInvalidResponsez÷Error class for responses which are not in the correct state.

    Args:
        response (object): The HTTP response which caused the failure.
        args (tuple): The positional arguments typically passed to an
            exception class.
    c                    ó   t t| ƒj|Ž  || _d S ©N)Úsuperr   Ú__init__Úresponse©Úselfr   Úargs©Ú	__class__© úV/var/www/html/loop/nvenv/lib/python3.10/site-packages/google/resumable_media/common.pyr   \   ó   zInvalidResponse.__init__©Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   Ú__classcell__r   r   r   r   r   S   ó    r   c                       r   )ÚDataCorruptionzâError class for corrupt media transfers.

    Args:
        response (object): The HTTP response which caused the failure.
        args (tuple): The positional arguments typically passed to an
            exception class.
    c                    r   r   )r   r   r   r   r	   r   r   r   r   k   r   zDataCorruption.__init__r   r   r   r   r   r   b   r   r   c                   @   s,   e Zd ZdZeddddfdd„Zdd„ ZdS )	ÚRetryStrategyaK  Configuration class for retrying failed requests.

    At most one of ``max_cumulative_retry`` and ``max_retries`` can be
    specified (they are both caps on the total number of retries). If
    neither are specified, then ``max_cumulative_retry`` is set as
    :data:`MAX_CUMULATIVE_RETRY`.

    Args:
        max_sleep (Optional[float]): The maximum amount of time to sleep after
            a failed request. Default is :attr:`MAX_SLEEP`.
        max_cumulative_retry (Optional[float]): The maximum **total** amount of
            time to sleep during retry process.
        max_retries (Optional[int]): The number of retries to attempt.
        initial_delay (Optional[float]): The initial delay. Default 1.0 second.
        muiltiplier (Optional[float]): Exponent of the backoff. Default is 2.0.

    Attributes:
        max_sleep (float): Maximum amount of time allowed between requests.
        max_cumulative_retry (Optional[float]): Maximum total sleep time
            allowed during retry process.
        max_retries (Optional[int]): The number retries to attempt.
        initial_delay (Optional[float]): The initial delay. Default 1.0 second.
        muiltiplier (Optional[float]): Exponent of the backoff. Default is 2.0.

    Raises:
        ValueError: If both of ``max_cumulative_retry`` and ``max_retries``
            are passed.
    Ng      ð?g       @c                 C   sN   |d ur|d urt tƒ‚|d u r|d u rt}|| _|| _|| _|| _|| _d S r   )Ú
ValueErrorÚ_SLEEP_RETRY_ERROR_MSGÚMAX_CUMULATIVE_RETRYÚ	max_sleepÚmax_cumulative_retryÚmax_retriesÚinitial_delayÚ
multiplier)r
   r   r   r   r    r!   r   r   r   r   �   s   
zRetryStrategy.__init__c                 C   s   | j du r
|| jkS || j kS )aù  Check if another retry is allowed.

        Args:
            total_sleep (float): With another retry, the amount of sleep that
                will be accumulated by the caller.
            num_retries (int): With another retry, the number of retries that
                will be attempted by the caller.

        Returns:
            bool: Indicating if another retry is allowed (depending on either
            the cumulative sleep allowed or the maximum number of retries
            allowed.
        N)r   r   )r
   Útotal_sleepÚnum_retriesr   r   r   Úretry_allowed¢   s   


zRetryStrategy.retry_allowed)r   r   r   r   Ú	MAX_SLEEPr   r$   r   r   r   r   r   q   s    
úr   )r   Úhttp.clientÚhttpr   ÚUPLOAD_CHUNK_SIZEÚclientÚPERMANENT_REDIRECTÚTOO_MANY_REQUESTSr%   r   ÚREQUEST_TIMEOUTÚINTERNAL_SERVER_ERRORÚBAD_GATEWAYÚSERVICE_UNAVAILABLEÚGATEWAY_TIMEOUTÚ	RETRYABLEÚ	Exceptionr   r   Úobjectr   r   r   r   r   Ú<module>   s2   ÿ
ú