o
    ˷e                     @   s   d Z ddlZddlZddlZddlmZ ddlmZ e	 Z
dZdZdZejjejjejjejjefZG dd	 d	eZG d
d deZdd ZdS )z}Shared utilities used by both downloads and uploads.

This utilities are explicitly catered to ``requests``-like transports.
    N)common)_helpersi    =   <   c                   @   s4   e Zd ZdZedd Zedd Zedd ZdS )	RequestsMixinzMix-in class implementing ``requests``-specific behavior.

    These are methods that are more general purpose, with implementations
    specific to the types defined in ``requests``.
    c                 C      | j S )zAccess the status code from an HTTP response.

        Args:
            response (~requests.Response): The HTTP response object.

        Returns:
            int: The status code.
        )status_coderesponse r   g/var/www/ideatree/venv/lib/python3.10/site-packages/google/resumable_media/requests/_request_helpers.py_get_status_code5      
zRequestsMixin._get_status_codec                 C   r   )a
  Access the headers from an HTTP response.

        Args:
            response (~requests.Response): The HTTP response object.

        Returns:
            ~requests.structures.CaseInsensitiveDict: The header mapping (keys
            are case-insensitive).
        )headersr	   r   r   r   _get_headersA   s   zRequestsMixin._get_headersc                 C   r   )Access the response body from an HTTP response.

        Args:
            response (~requests.Response): The HTTP response object.

        Returns:
            bytes: The body of the ``response``.
        )contentr	   r   r   r   	_get_bodyN   r   zRequestsMixin._get_bodyN)__name__
__module____qualname____doc__staticmethodr   r   r   r   r   r   r   r   .   s    

r   c                   @   s   e Zd Zedd ZdS )RawRequestsMixinc                 C   s.   | j du rd| jjtdd| _ d| _| j S )r   F    )decode_contentT)_contentjoinrawstream_SINGLE_GET_CHUNK_SIZE_content_consumedr	   r   r   r   r   \   s   

zRawRequestsMixin._get_bodyN)r   r   r   r   r   r   r   r   r   r   [   s    r   c           
   
   C   s   d}d}t |j|j }	 d}z|  }W |S  ty) } z|}W Y d}~n#d}~w tjyG } z||jtjv r<|}n W Y d}~nd}~ww t	||j
|j\}}	|d7 }||	7 }|||sc|t|	 q)a.  Attempts to retry a call to ``func`` until success.

    Expects ``func`` to return an HTTP response and uses ``get_status_code``
    to check if the response is retry-able.

    ``func`` is expected to raise a failure status code as a
    common.InvalidResponse, at which point this method will check the code
    against the common.RETRIABLE list of retriable status codes.

    Will retry until :meth:`~.RetryStrategy.retry_allowed` (on the current
    ``retry_strategy``) returns :data:`False`. Uses
    :func:`_helpers.calculate_retry_wait` to double the wait time (with jitter)
    after each attempt.

    Args:
        func (Callable): A callable that takes no arguments and produces
            an HTTP response which will be checked as retry-able.
        get_status_code (Callable[Any, int]): Helper to get a status code
            from a response.
        retry_strategy (~google.resumable_media.common.RetryStrategy): The
            strategy to use if the request fails and must be retried.

    Returns:
        object: The return value of ``func``.
    g        r   TN   )floatinitial_delay
multiplier_CONNECTION_ERROR_CLASSESr   InvalidResponser
   	RETRYABLEr   calculate_retry_wait	max_sleepretry_allowedtimesleep)
funcget_status_coderetry_strategytotal_sleepnum_retries	base_waiterrorr
   e	wait_timer   r   r   wait_and_retryn   s6   

r7   )r   requests.exceptionsrequestsurllib3.exceptionsurllib3r,   google.resumable_mediar   r   RetryStrategy_DEFAULT_RETRY_STRATEGYr    _DEFAULT_CONNECT_TIMEOUT_DEFAULT_READ_TIMEOUT
exceptionsConnectionErrorChunkedEncodingErrorTimeoutProtocolErrorr&   objectr   r   r7   r   r   r   r   <module>   s&   	-