B
    uf/                 @   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 )zCommon 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                   s    e Zd ZdZ fddZ  ZS )InvalidResponsezError 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                s   t t| j|  || _d S )N)superr   __init__response)selfr   args)	__class__ _/home/ankuromar296_gmail_com/myenv/lib/python3.7/site-packages/google/resumable_media/common.pyr   \   s    zInvalidResponse.__init__)__name__
__module____qualname____doc__r   __classcell__r	   r	   )r   r
   r   S   s   r   c                   s    e Zd ZdZ fddZ  ZS )DataCorruptionzError 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                s   t t| j|  || _d S )N)r   r   r   r   )r   r   r   )r   r	   r
   r   k   s    zDataCorruption.__init__)r   r   r   r   r   r   r	   r	   )r   r
   r   b   s   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 k	r|d k	rt t|d kr,|d kr,t}|| _|| _|| _|| _|| _d S )N)
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kr|| jkS || j kS d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   Ztotal_sleepZ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   ZUPLOAD_CHUNK_SIZEclientPERMANENT_REDIRECTTOO_MANY_REQUESTSr   r   REQUEST_TIMEOUTINTERNAL_SERVER_ERRORBAD_GATEWAYSERVICE_UNAVAILABLEGATEWAY_TIMEOUTZ	RETRYABLE	Exceptionr   r   objectr   r	   r	   r	   r
   <module>   s    
	