Ë
    ñ%9j9  ã                   ó<  — d Z ddlmZ ddlZddlZddlZddlZddlZddlm	Z	 ddlm
Z
 ddlmZ ddlmZ ddlmZ d	Zd
Zd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#d„Zd„ Zd„ Zd„ Z d„ Z!d„ Z"d„ Z#d„ Z$d„ Z%d„ Z&d„ Z'd„ Z(d „ Z) G d!„ d"e*«      Z+y)$z4Shared utilities used by both downloads and uploads.é    )Úabsolute_importN)Úparse_qs)Ú	urlencode)Úurlsplit)Ú
urlunsplit)ÚcommonÚrangezcontent-rangezcontent-encodingz¨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-generationzx-goog-hashzx-goog-stored-content-encodingz·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   ó    ú[/var/www/html/truck-me/venv/lib/python3.12/site-packages/google/resumable_media/_helpers.pyÚ
do_nothingr   5   ó   � 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   9   sB   € ñ& ˜(Ó#€GØ�7ÑÙŒ
Ü×$Ñ$ØÐ<¸dó
ð 	
ð �4‰=Ðr   c                 ó‚   —  || «      }||vr2|t         j                  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 of)r   Ú	RETRYABLEr   )r   Ústatus_codesÚget_status_coder   Ústatus_codes        r   Úrequire_status_coder   V   sZ   € ñ$ " (Ó+€KØ˜,Ñ&Øœf×.Ñ.Ñ.ÙŒJÜ×$Ñ$ØØ-ØØð	
ð
 ò
ð 	
ð Ðr   c                 óZ   — || 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 multiplied until it reaches the maximum sleep.
        max_sleep (float): Maximum value that a sleep time is allowed to be.
        multiplier (float): Multiplier to apply to the base wait.

    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).
    r   iè  gü©ñÒMbP?)ÚrandomÚrandint)Ú	base_waitÚ	max_sleepÚ
multiplierÚnew_base_waitÚ	jitter_mss        r   Úcalculate_retry_waitr&   v   s@   € ð(  Ñ*€MØ�yÒ Ø!ˆä—‘˜q $Ó'€IØ˜-¨%°)Ñ*;Ñ;Ð;Ð;r   c                  óÔ   — 	 ddl } | j                  «       }|S # t        $ rF 	 ddl}|j                  j                  d«      }t        «        Y |S # t        $ r t        d«      ‚w xY ww xY w)zªGet crc32c object
    Attempt to use the Google-CRC32c package. If it isn't available, try
    to use CRCMod. CRCMod might be using a 'slow' varietal. If so, warn...
    r   Nzcrc-32cz3Failed to import either `google-crc32c` or `crcmod`)Úgoogle_crc32cÚChecksumÚImportErrorÚcrcmodÚ
predefinedÚCrcÚ_is_fast_crcmod)r(   Úcrc_objr+   s      r   Ú_get_crc32c_objectr0   ’   s~   € ð
UÛà×(Ñ(Ó*ˆð €Nøô ò Uð	UÛà×'Ñ'×+Ñ+¨IÓ6ˆGÜÕð
 €Nøô ò 	UÜÐSÓTÐTð	UúðUús   ‚ ˜	A'¢)AÁA#Á#A'c                  ó¤   — t        dt        «       t        «       dgd«      } t        | dd«      }|s t	        j
                  t        t        d¬«       |S )Nzcrcmod.crcmodÚ_usingExtensionr   Fé   )Ú
stacklevel)Ú
__import__ÚglobalsÚlocalsÚgetattrÚwarningsÚwarnÚ_SLOW_CRC32C_WARNINGÚRuntimeWarning)Únested_crcmodÚfast_crcs     r   r.   r.   ¨   sL   € äØÜ‹	Ü‹Ø	ÐØ	ó€Mô �}Ð&7¸Ó?€HÙÜ�‰Ô*¬NÀqÕIØ€Or   c                 ó   — | dk(  ry| S )NÚmd5Úmd5Hashr   ©Úchecksum_types    r   Ú_get_metadata_keyrD   ·   s   € Ø˜ÒØàÐr   c                 óN   — t        j                  | «      }|j                  d«      S )zÈConvert a checksum object into a digest encoded for an HTTP header.

    Args:
        bytes: A checksum digest bytestring.

    Returns:
        str: A base64 string representation of the input.
    zutf-8)Úbase64Ú	b64encodeÚdecode)Údigest_bytestringÚencoded_digests     r   Úprepare_checksum_digestrK   ¾   s&   € ô ×%Ñ%Ð&7Ó8€Nà× Ñ  Ó)Ð)r   c                 ó„  — |dvrt        d«      ‚|dv rž || «      }t        |j                  t        «      | |¬«      }|€Ht        j                  ||j                  «       ¬«      }t        j                  |«       t        «       }||fS |dk(  rt        j                  «       }||fS t        «       }||fS d}t        «       }||fS )aÒ  Get the expected checksum and checksum object for the download response.

    Args:
        response (~requests.Response): The HTTP response object.
        get_headers (callable: response->dict): returns response headers.
        media_url (str): The URL containing the media to be downloaded.
        checksum_type Optional(str): The checksum type to read from the headers,
            exactly as it will appear in the headers (case-sensitive). Must be
            "md5", "crc32c" or None.

    Returns:
        Tuple (Optional[str], object): The expected checksum of the response,
        if it can be detected from the ``X-Goog-Hash`` header, and the
        appropriate checksum object for the expected checksum.
    ©r@   Úcrc32cNú4checksum must be ``'md5'``, ``'crc32c'`` or ``None``©r@   rN   ©Úchecksum_labelNrB   r@   )Ú
ValueErrorÚ_parse_checksum_headerÚgetÚ_HASH_HEADERÚ_MISSING_CHECKSUMÚformatÚupperÚ_LOGGERÚinfoÚ_DoNothingHashÚhashlibr@   r0   )r   r   Ú	media_urlrC   r   Úexpected_checksumÚmsgÚchecksum_objects           r   Ú_get_expected_checksumrb   Ì   sé   € ð  Ð3Ñ3ÜÐOÓPÐPØ	Ð+Ñ	+Ù˜hÓ'ˆÜ2Ø�K‰KœÓ% xÀô
Ðð Ð$Ü#×*Ñ*Ø¨×)<Ñ)<Ó)>ð +ó ˆCô �L‰L˜ÔÜ,Ó.ˆOð ˜Ð/Ð/ð  Ò%Ü")§+¡+£-�ð ˜Ð/Ð/ô #5Ó"6�ð
 ˜Ð/Ð/ð !ÐÜ(Ó*ˆà˜Ð/Ð/r   c                 ó†   — |dvrt        d«      ‚|dv r+ || «      }t        |j                  t        «      | |¬«      }|S d}|S )a�  Get the computed checksum and checksum object from the response headers.

    Args:
        response (~requests.Response): The HTTP response object.
        get_headers (callable: response->dict): returns response headers.
        checksum_type Optional(str): The checksum type to read from the headers,
            exactly as it will appear in the headers (case-sensitive). Must be
            "md5", "crc32c" or None.

    Returns:
        Tuple (Optional[str], object): The checksum of the response,
        if it can be detected from the ``X-Goog-Hash`` header, and the
        appropriate checksum object for the expected checksum.
    rM   rO   rP   rQ   N)rS   rT   rU   rV   )r   r   rC   r   Úremote_checksums        r   Ú#_get_uploaded_checksum_from_headersre   ö   s[   € ð Ð3Ñ3ÜÐOÓPÐPØ	Ð+Ñ	+Ù˜hÓ'ˆÜ0Ø�K‰KœÓ% xÀô
ˆð Ðð ˆàÐr   c                 ó>  — | €yg }| j                  d«      D ]<  }|j                  dd«      \  }}|j                  «       |k(  sŒ,|j                  |«       Œ> t        |«      dk(  ryt        |«      dk(  r|d   S t	        j
                  |dj                  |«      | |«      ‚)aD  Parses the checksum header from an ``X-Goog-Hash`` value.

    .. _header reference: https://cloud.google.com/storage/docs/                          xml-api/reference-headers#xgooghash

    Expects ``header_value`` (if not :data:`None`) to be in one of the three
    following formats:

    * ``crc32c=n03x6A==``
    * ``md5=Ojk9c3dhfxgoKVVHYwFbHQ==``
    * ``crc32c=n03x6A==,md5=Ojk9c3dhfxgoKVVHYwFbHQ==``

    See the `header reference`_ for more information.

    Args:
        header_value (Optional[str]): The ``X-Goog-Hash`` header from
            a download response.
        response (~requests.Response): The HTTP response object.
        checksum_label (str): The label of the header value to read, as in the
            examples above. Typically "md5" or "crc32c"

    Returns:
        Optional[str]: The expected checksum of the response, if it
        can be detected from the ``X-Goog-Hash`` header; otherwise, None.

    Raises:
        ~google.resumable_media.common.InvalidResponse: If there are
            multiple checksums of the requested type in ``header_value``.
    Nú,ú=é   r   z.X-Goog-Hash header had multiple ``{}`` values.)ÚsplitÚlstripÚappendÚlenr   r   rX   )Úheader_valuer   rR   ÚmatchesÚchecksumr   Úvalues          r   rT   rT     s«   € ð< ÐØà€GØ ×&Ñ& sÓ+ò "ˆØ—n‘n S¨!Ó,‰ˆˆeà�;‰;‹=˜NÓ*Ø�N‰N˜5Õ!ð	"ô ˆ7ƒ|�qÒØÜ	ˆW‹˜Ò	Ø�q‰zÐä×$Ñ$ØØ<×CÑCÀNÓSØØó	
ð 	
r   c                 ón   — | dk(  rt        j                  «       S | dk(  r
t        «       S | €yt        d«      ‚)z~Respond with a checksum object for a supported type, if not None.

    Raises ValueError if checksum_type is unsupported.
    r@   rN   NrO   )r]   r@   r0   rS   rB   s    r   Ú_get_checksum_objectrs   G  s>   € ð
 ˜ÒÜ�{‰{‹}ÐØ	˜(Ò	"Ü!Ó#Ð#Ø	Ð	ØäÐOÓPÐPr   c                 óZ   —  || «      }|j                  t        d«      }|€yt        |«      S )a�  Parses the generation header from an ``X-Goog-Generation`` value.

    Args:
        response (~requests.Response): The HTTP response object.
        get_headers (callable: response->dict): returns response headers.

    Returns:
        Optional[long]: The object generation from the response, if it
        can be detected from the ``X-Goog-Generation`` header; otherwise, None.
    N)rU   Ú_GENERATION_HEADERÚint)r   r   r   Úobject_generations       r   Ú_parse_generation_headerrx   V  s5   € ñ ˜(Ó#€GØŸ™Ô$6¸Ó=ÐàÐ ØäÐ$Ó%Ð%r   c                 ó€   — t        | «      \  }}}}}t        |«      }|j                  dd«      }|€yt        |d   «      S )zÿRetrieve the object generation query param specified in the media url.

    Args:
        media_url (str): The URL containing the media to be downloaded.

    Returns:
        long: The object generation from the media url if exists; otherwise, None.
    Ú
generationNr   )r   r   rU   rv   )r^   Ú_ÚqueryÚquery_paramsrw   s        r   Ú_get_generation_from_urlr~   j  sO   € ô ! Ó+Ñ€A€qˆ!ˆU�AÜ˜E“?€LØ$×(Ñ(¨°tÓ<ÐàÐ ØäÐ$ QÑ'Ó(Ð(r   c                 ó    — t        |«      dk(  r| S t        | «      \  }}}}}t        |«      }i |¥|¥}t        |d¬«      }t	        |||||f«      S )a  Add query parameters to a base url.

    Args:
        media_url (str): The URL containing the media to be downloaded.
        query_params (dict): Names and values of the query parameters to add.

    Returns:
        str: URL with additional query strings appended.
    r   T)Údoseq)rm   r   r   r   r   )	r^   r}   ÚschemeÚnetlocÚpathr|   ÚfragÚparamsÚ
new_paramss	            r   Úadd_query_parametersr‡   ~  sf   € ô ˆ<Ó˜AÒØÐä(0°Ó(;Ñ%€FˆF�D˜% Ü�e‹_€FØ+�FÐ+˜lÐ+€JÜ�j¨Ô-€EÜ�v˜v t¨U°DÐ9Ó:Ð:r   c                 óv   —  || «      }|j                  t        «      dk(  xr |j                  t        «      dk7  S )a  Returns True if the object was served decompressed. This happens when the
    "x-goog-stored-content-encoding" header is "gzip" and "content-encoding" header
    is not "gzip". See more at: https://cloud.google.com/storage/docs/transcoding#transcoding_and_gzip
    Args:
        response (~requests.Response): The HTTP response object.
        get_headers (callable: response->dict): returns response headers.
    Returns:
        bool: Returns True if decompressive transcoding has occurred; otherwise, False.
    Úgzip)rU   Ú_STORED_CONTENT_ENCODING_HEADERÚCONTENT_ENCODING_HEADER)r   r   r   s      r   Ú_is_decompressive_transcodingrŒ   “  s<   € ñ ˜(Ó#€Gà�‰Ô3Ó4¸Ñ>ò 	;Ø�K‰KÔ/Ó0°FÑ:ðr   c                   ó   — e Zd ZdZd„ Zy)r\   z«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__r‘   r   r   r   r\   r\   ¤  s   „ ñór   r\   )g       @),r•   Ú
__future__r   rF   r]   Úloggingr   r9   Úurllib.parser   r   r   r   Úgoogle.resumable_mediar   ÚRANGE_HEADERÚCONTENT_RANGE_HEADERr‹   r;   ru   rV   rŠ   rW   Ú	getLoggerr’   rZ   r   r   r   r&   r0   r.   rD   rK   rb   re   rT   rs   rx   r~   r‡   rŒ   Úobjectr\   r   r   r   ú<module>rž      sä   ðñ ;å &ã Û Û Û Û å !Ý "Ý !Ý #å )ð €Ø&Ð Ø,Ð ð-ð ð
 )Ð Ø€Ø"BÐ ð$Ð ð ˆ'×
Ñ
˜HÓ
%€ò#ð ;Eó ð: KUó ó@<ò8ò,òò*ò'0òTò82
òjQò&ò()ò(;ò*ô"�Võ r   