Ë
    T¼Sf¬  ã                   ó    — d Z ddlZddlZddlZddlmZ dZdZdZdZ	dZ
 ej                  e«      Zd	„ Zefd
„Zefd„Zd„ Zd„ Z G d„ de«      Zy)z4Shared utilities used by both downloads and uploads.é    N)ÚcommonÚrangezcontent-rangez¨Currently using crcmod in pure python form. This is a slow implementation. Python 3 has a faster implementation, `google-crc32c`, which will be used if it is installed.zx-goog-hashz·No {checksum_type} checksum was returned from the service while downloading {}
(which happens for composite objects), so client-side content integrity
checking is not being performed.c                   ó   — y)zSimple default callback.N© r   ó    úeC:\Users\user\Documents\project_loop\venv\Lib\site-packages\google/_async_resumable_media/_helpers.pyÚ
do_nothingr	   )   ó   � r   c                 ó`   —  || «      }||vr |«        t        j                  | d|«      ‚||   S )aš  Checks that a specific header is in a headers dictionary.

    Args:
        response (object): An HTTP response object, expected to have a
            ``headers`` attribute that is a ``Mapping[str, str]``.
        name (str): The name of a required header.
        get_headers (Callable[Any, Mapping[str, str]]): Helper to get headers
            from an HTTP response.
        callback (Optional[Callable]): A callback that takes no arguments,
            to be executed when an exception is being raised.

    Returns:
        str: The desired header.

    Raises:
        ~google.resumable_media.common.InvalidResponse: If the header
            is missing.
    z$Response headers must contain header©r   ÚInvalidResponse)ÚresponseÚnameÚget_headersÚcallbackÚheaderss        r   Úheader_requiredr   -   sB   € ñ& ˜(Ó#€GØ�7ÑÙŒ
Ü×$Ñ$ØÐ<¸dó
ð 	
ð �4‰=Ðr   c                 ó^   —  || «      }||vr  |«        t        j                  | d|dg|¢­Ž ‚|S )a`  Require a response has a status code among a list.

    Args:
        response (object): The HTTP response object.
        status_codes (tuple): The acceptable status codes.
        get_status_code (Callable[Any, int]): Helper to get a status code
            from a response.
        callback (Optional[Callable]): A callback that takes no arguments,
            to be executed when an exception is being raised.

    Returns:
        int: The status code.

    Raises:
        ~google.resumable_media.common.InvalidResponse: If the status code
            is not one of the values in ``status_codes``.
    zRequest failed with status codezExpected one ofr   )r   Ústatus_codesÚget_status_coder   Ústatus_codes        r   Úrequire_status_coder   J   sL   € ñ$ " (Ó+€KØ˜,Ñ&ÙŒ
Ü×$Ñ$ØØ-ØØð	
ð
 ò
ð 	
ð Ðr   c                 óZ   — d| z  }||kD  r|}t        j                  dd«      }||d|z  z   fS )aµ  Calculate the amount of time to wait before a retry attempt.

    Wait time grows exponentially with the number of attempts, until
    ``max_sleep``.

    A random amount of jitter (between 0 and 1 seconds) is added to spread out
    retry attempts from different clients.

    Args:
        base_wait (float): The "base" wait time (i.e. without any jitter)
            that will be doubled until it reaches the maximum sleep.
        max_sleep (float): Maximum value that a sleep time is allowed to be.

    Returns:
        Tuple[float, float]: The new base wait time as well as the wait time
        to be applied (with a random amount of jitter between 0 and 1 seconds
        added).
    g       @r   iè  gü©ñÒMbP?)ÚrandomÚrandint)Ú	base_waitÚ	max_sleepÚnew_base_waitÚ	jitter_mss       r   Úcalculate_retry_waitr    i   s?   € ð& ˜)‘O€MØ�yÒ Ø!ˆä—‘˜q $Ó'€IØ˜-¨%°)Ñ*;Ñ;Ð;Ð;r   c              ƒ   óF  K  — d}d}d}	 d}	  | «       ƒ d{  –—† } ||«      t         j                  vr|S |j                  ||«      s|r|‚S t	        ||j
                  «      \  }}	|dz  }||	z  }t        j                  |	«       Œ}7 Œo# t        $ r}|}Y d}~Œcd}~ww xY w­w)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.

    Will retry until :meth:`~.RetryStrategy.retry_allowed` (on the current
    ``retry_strategy``) returns :data:`False`. Uses
    :func:`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   g      à?Né   )r   Ú	RETRYABLEÚConnectionErrorÚretry_allowedr    r   ÚtimeÚsleep)
Úfuncr   Úretry_strategyÚtotal_sleepÚnum_retriesr   Úerrorr   ÚeÚ	wait_times
             r   Úwait_and_retryr/   „   s»   è ø€ ð. €KØ€KØ€Ià
Øˆð	 Ù!›V—|ˆHñ ˜xÓ(´×0@Ñ0@Ñ@Ø�à×+Ñ+¨K¸ÔEñ Ø�àˆOä3°I¸~×?WÑ?WÓXÑˆ	�9à�qÑˆØ�yÑ ˆÜ�
‰
�9Ôð- ð $ùÜò 	Ø�Eûð	üs>   ‚
B!�
B	 —B˜B	 œA+B!ÂB	 Â		BÂBÂB!ÂBÂB!c                   ó   — e Zd ZdZd„ Zy)Ú_DoNothingHashz«Do-nothing hash object.

    Intended as a stand-in for ``hashlib.md5`` or a crc32c checksum
    implementation in cases where it isn't necessary to compute the hash.
    c                  ó   — y)z¸Do-nothing ``update`` method.

        Intended to match the interface of ``hashlib.md5`` and other checksums.
        Args:
            unused_chunk (bytes): A chunk of data.
        Nr   )ÚselfÚunused_chunks     r   Úupdatez_DoNothingHash.update¿   r
   r   N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r5   r   r   r   r1   r1   ¸   s   „ ñór   r1   )r9   Úloggingr   r&   Úgoogle.resumable_mediar   ÚRANGE_HEADERÚCONTENT_RANGE_HEADERÚ_SLOW_CRC32C_WARNINGÚ_HASH_HEADERÚ_MISSING_CHECKSUMÚ	getLoggerr6   Ú_LOGGERr	   r   r   r    r/   Úobjectr1   r   r   r   ú<module>rD      s…   ðñ ;ã Û Û õ *ð €Ø&Ð ð-ð ð
 €ð$Ð ð ˆ'×
Ñ
˜HÓ
%€ò#ð ;Eó ð: KUó ò><ò61ôh�Võ r   