
    (phv                        S r SSKrSSKrSSKJr  SSKJr  SSKJr  SSKJ	r	  Sr
SrS	r " S
 S\	R                  \R                  5      r " S S\	R                  \R                  5      r " S S\	R                  \R"                  5      r " S S\	R                  \R"                  5      rS r " S S\R(                  R*                  5      r\" \R(                  S5      (       a   " S S5      rgSrg)z/Support for downloading media from Google APIs.    N)	_download)common)_helpers)_request_helperszChecksum mismatch while downloading:

  {}

The X-Goog-Hash header indicated an {checksum_type} checksum of:

  {}

but the actual {checksum_type} checksum of the downloaded contents was:

  {}
zIncomplete download for:
{}
Error writing to stream while handling a gzip-compressed file download.
Please restart the download.
z
The X-Goog-Stored-Content-Length is {}. The X-Goog-Stored-Content-Encoding is {}.

The download request read {} bytes of data.
If the download was incomplete, please check the network connection and restart the download.
c                   V    \ rS rSrSrS r\R                  \R                  44S jr	Sr
g)Download8   ad  Helper to manage downloading a resource from a Google API.

"Slices" of the resource can be retrieved by specifying a range
with ``start`` and / or ``end``. However, in typical usage, neither
``start`` nor ``end`` is expected to be provided.

Args:
    media_url (str): The URL containing the media to be downloaded.
    stream (IO[bytes]): A write-able stream (i.e. file-like object) that
        the downloaded resource can be written to.
    start (int): The first byte in a range to be downloaded. If not
        provided, but ``end`` is provided, will download from the
        beginning to ``end`` of the media.
    end (int): The last byte in a range to be downloaded. If not
        provided, but ``start`` is provided, will download from the
        ``start`` to the end of the media.
    headers (Optional[Mapping[str, str]]): Extra headers that should
        be sent with the request, e.g. headers for encrypted data.
    checksum Optional([str]): The type of checksum to compute to verify
        the integrity of the object. The response headers must contain
        a checksum of the requested type. If the headers lack an
        appropriate checksum (for instance in the case of transcoded or
        ranged downloads where the remote service does not know the
        correct checksum) an INFO-level log will be emitted. Supported
        values are "md5", "crc32c" and None. The default is "md5".

Attributes:
    media_url (str): The URL containing the media to be downloaded.
    start (Optional[int]): The first byte in a range to be downloaded.
    end (Optional[int]): The last byte in a range to be downloaded.
c                    U R                   cP  U R                  cC  [        R                  " XR                  U R
                  U R                  S9u  p#X l         X0l        OU R                   nU R                  nU   [        UR                  U5      nUR                  [        R                  SS9nU HM  nU R                  R                  U5        U =R                  [        U5      -  sl        UR!                  U5        MO     SSS5        UGb*  UR"                  [$        R&                  R(                  :w  Ga   [        R*                  " UR-                  5       5      nXr:w  a  U R	                  U5      nUR/                  S5      n	UR/                  S5      n
[0        R3                  XU R                  5      nU
(       a*  U R                  [5        U
5      :  a  U	S:w  a  [7        U5      e[8        R3                  U R
                  UUU R                  R;                  5       S9nX-  n[<        R>                  " X5      eggg! , (       d  f       GN>= f)b  Write response body to a write-able stream.

.. note:

    This method assumes that the ``_stream`` attribute is set on the
    current download.

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

Raises:
    ~google.resumable_media.common.DataCorruption: If the download's
        checksum doesn't agree with server-computed checksum.
Nchecksum_typeF)
chunk_sizedecode_unicodex-goog-stored-content-encodingx-goog-stored-content-lengthgzip) _expected_checksum_checksum_objectr   _get_expected_checksum_get_headers	media_urlchecksum_add_decoderrawiter_contentr   _SINGLE_GET_CHUNK_SIZE_streamwrite_bytes_downloadedlenupdatestatus_codehttpclientPARTIAL_CONTENTprepare_checksum_digestdigestget_RESPONSE_HEADERS_INFOformatintConnectionError_CHECKSUM_MISMATCHupperr   DataCorruption)selfresponseexpected_checksumchecksum_objectlocal_checksum_object	body_iterchunkactual_checksumheadersx_goog_encodingx_goog_lengthcontent_length_msgmsgs                [/var/www/html/venv/lib/python3.13/site-packages/google/resumable_media/requests/download.py_write_to_streamDownload._write_to_streamY   s   ( ""*t/D/D/L 2:1P1P++T^^4==2. '8#$3! $ 7 7"33O
 %1$O! --+BBSX . I #""5)&&#e*4&%,,U3 #   )$$(C(CC&>>?U?U?WXO3++H5")++.N"O ',J K%;%B%B!D4J4J&" "..]1CC'61
 **<==,33)'&*mm&9&9&;	 4 C -C //>>1 4	 D *! Xs   8BH77
Ic                 0  ^ ^^^ T R                  5       u  mp4nUUUS.mT R                  b  STS'   T R                  c%  [        R                  " T R
                  5      T l        UUU U4S jn[        R                  " UT R                  T R                  5      $ )  Consume the resource to be downloaded.

If a ``stream`` is attached to this download, then the downloaded
resource will be written to the stream.

Args:
    transport (~requests.Session): A ``requests`` object which can
        make authenticated requests.
    timeout (Optional[Union[float, Tuple[float, float]]]):
        The number of seconds to wait for the server response.
        Depending on the retry strategy, a request may be repeated
        several times using the same timeout each time.

        Can also be passed as a tuple (connect_timeout, read_timeout).
        See :meth:`requests.Session.request` documentation for details.

Returns:
    ~requests.Response: The HTTP response returned by ``transport``.

Raises:
    ~google.resumable_media.common.DataCorruption: If the download's
        checksum doesn't agree with server-computed checksum.
    ValueError: If the current :class:`Download` has already
        finished.
datar8   timeoutTstreamc                    > TR                   n TR                  S:  a  [        R                  " TR                  =(       d    STR                  -   TR
                  TR                  5        TR                  TS'   TR                  bP  [        R                  " TR                   5      c/  STR                  0n[        R                  " TR                   U5      n TR                  " TU 40 TD6nTR                  c&  [        R                  " UTR                  5      Tl        TR                  U5        TR                  bZ  [        R                   " UTR                  5      (       a#   TR                  R#                  S5        STl        TR+                  U5        U$ ! [$         a&  n[&        R)                  U 5      n[%        U5      UeS nAff = fNr   r8   
generationr   r   r   add_bytes_rangestartend_headers_object_generationr   _get_generation_from_urladd_query_parametersrequest_parse_generation_headerr   _process_responser   _is_decompressive_transcodingseek	Exception_STREAM_SEEK_ERRORr*   r>   	urlquery_paramresultexcr<   methodrequest_kwargsr0   	transports	        r=   retriable_request+Download.consume.<locals>.retriable_request      ..C %%)))ZZ_1(>(>>$-- -1MMy) ++7 99$..IQ#/1H1H"IK"77TC&&vsEnEF &&.*2*K*KD--+' ""6*
 ||'99&$BSBSTT6))!, ./D*%%f-M % 6077<'n#56   "F 
G!!GG)
_prepare_requestr   rN   r   rO   r   r   wait_and_retry_get_status_code_retry_strategy	r0   r_   rD   _payloadr8   r`   r]   r^   s	   ``     @@r=   consumeDownload.consume   s    B '+&;&;&=#G 

 <<#'+N8$ ""*&.&G&G&WD#,	 ,	\  ..t44d6J6J
 	
    r   r   r   rN   N__name__
__module____qualname____firstlineno____doc__r>   r   _DEFAULT_CONNECT_TIMEOUT_DEFAULT_READ_TIMEOUTrk   __static_attributes__ rm   r=   r   r   8   s.    @N?h 5522
`
rm   r   c                   V    \ rS rSrSrS r\R                  \R                  44S jr	Sr
g)RawDownloadi  ag  Helper to manage downloading a raw resource from a Google API.

"Slices" of the resource can be retrieved by specifying a range
with ``start`` and / or ``end``. However, in typical usage, neither
``start`` nor ``end`` is expected to be provided.

Args:
    media_url (str): The URL containing the media to be downloaded.
    stream (IO[bytes]): A write-able stream (i.e. file-like object) that
        the downloaded resource can be written to.
    start (int): The first byte in a range to be downloaded. If not
        provided, but ``end`` is provided, will download from the
        beginning to ``end`` of the media.
    end (int): The last byte in a range to be downloaded. If not
        provided, but ``start`` is provided, will download from the
        ``start`` to the end of the media.
    headers (Optional[Mapping[str, str]]): Extra headers that should
        be sent with the request, e.g. headers for encrypted data.
    checksum Optional([str]): The type of checksum to compute to verify
        the integrity of the object. The response headers must contain
        a checksum of the requested type. If the headers lack an
        appropriate checksum (for instance in the case of transcoded or
        ranged downloads where the remote service does not know the
        correct checksum) an INFO-level log will be emitted. Supported
        values are "md5", "crc32c" and None. The default is "md5".
Attributes:
    media_url (str): The URL containing the media to be downloaded.
    start (Optional[int]): The first byte in a range to be downloaded.
    end (Optional[int]): The last byte in a range to be downloaded.
c                    U R                   cP  U R                  cC  [        R                  " XR                  U R
                  U R                  S9u  p#X l         X0l        OU R                   nU R                  nU   UR                  R                  [        R                  SS9nU HM  nU R                  R                  U5        U =R                  [        U5      -  sl        UR                  U5        MO     SUl        SSS5        UGb*  UR"                  [$        R&                  R(                  :w  Ga   [        R*                  " UR-                  5       5      nXb:w  a  U R	                  U5      nUR/                  S5      nUR/                  S5      n	[0        R3                  XU R                  5      n
U	(       a*  U R                  [5        U	5      :  a  US:w  a  [7        U
5      e[8        R3                  U R
                  UUU R                  R;                  5       S9nX-  n[<        R>                  " X5      eggg! , (       d  f       GN>= f)	r   Nr   F)decode_contentTr   r   r   ) r   r   r   r   r   r   r   r   rE   r   r   r   r   r   r    r!   _content_consumedr"   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   r.   r   r/   )r0   r1   r2   r3   r5   r6   r7   r8   r9   r:   r;   r<   s               r=   r>   RawDownload._write_to_stream,  s   & ""*t/D/D/L 2:1P1P++T^^4==2. '8#$3! $ 7 7"33O ++ 77 , I #""5)&&#e*4&&&u- # *.H&  )$$(C(CC&>>?U?U?WXO3++H5")++.N"O ',J K%;%B%B!D4J4J&" "..]1CC'61
 **<==,33)'&*mm&9&9&;	 4 C -C //>>1 4	 D * Xs   8BH22
Ic                   ^ ^^^ T R                  5       u  mp4nUUUSS.mT R                  c%  [        R                  " T R                  5      T l        UUU U4S jn[
        R                  " UT R                  T R                  5      $ )rA   T)rC   r8   rD   rE   c                    > TR                   n TR                  S:  a  [        R                  " TR                  =(       d    STR                  -   TR
                  TR                  5        TR                  TS'   TR                  bP  [        R                  " TR                   5      c/  STR                  0n[        R                  " TR                   U5      n TR                  " TU 40 TD6nTR                  c&  [        R                  " UTR                  5      Tl        TR                  U5        TR                  bZ  [        R                   " UTR                  5      (       a#   TR                  R#                  S5        STl        TR+                  U5        U$ ! [$         a&  n[&        R)                  U 5      n[%        U5      UeS nAff = frG   rI   rX   s	        r=   r`   .RawDownload.consume.<locals>.retriable_request  rb   rc   )	rd   rN   r   rO   r   r   re   rf   rg   rh   s	   ``     @@r=   rk   RawDownload.consumew  s    B '+&;&;&=#G 	
 ""*&.&G&G&WD#,	 ,	\  ..t44d6J6J
 	
rm   rn   Nro   rx   rm   r=   rz   rz     s-    >I?^ 5522
_
rm   rz   c                   P    \ rS rSrSr\R                  \R                  44S jrSr	g)ChunkedDownloadi  aN  Download a resource in chunks from a Google API.

Args:
    media_url (str): The URL containing the media to be downloaded.
    chunk_size (int): The number of bytes to be retrieved in each
        request.
    stream (IO[bytes]): A write-able stream (i.e. file-like object) that
        will be used to concatenate chunks of the resource as they are
        downloaded.
    start (int): The first byte in a range to be downloaded. If not
        provided, defaults to ``0``.
    end (int): The last byte in a range to be downloaded. If not
        provided, will download to the end of the media.
    headers (Optional[Mapping[str, str]]): Extra headers that should
        be sent with each request, e.g. headers for data encryption
        key headers.

Attributes:
    media_url (str): The URL containing the media to be downloaded.
    start (Optional[int]): The first byte in a range to be downloaded.
    end (Optional[int]): The last byte in a range to be downloaded.
    chunk_size (int): The number of bytes to be retrieved in each request.

Raises:
    ValueError: If ``start`` is negative.
c                    ^ ^^^^^^ T R                  5       u  mmmmUUUU UUU4S jn[        R                  " UT R                  T R                  5      $ )  Consume the next chunk of the resource to be downloaded.

Args:
    transport (~requests.Session): A ``requests`` object which can
        make authenticated requests.
    timeout (Optional[Union[float, Tuple[float, float]]]):
        The number of seconds to wait for the server response.
        Depending on the retry strategy, a request may be repeated
        several times using the same timeout each time.

        Can also be passed as a tuple (connect_timeout, read_timeout).
        See :meth:`requests.Session.request` documentation for details.

Returns:
    ~requests.Response: The HTTP response returned by ``transport``.

Raises:
    ValueError: If the current download has finished.
c                  P   > TR                  TTTTTS9n TR                  U 5        U $ )NrB   rQ   rS   r[   r8   r]   rj   r0   rD   r_   rY   s    r=   r`   =ChunkedDownload.consume_next_chunk.<locals>.retriable_request  s<    && ' F ""6*Mrm   rd   r   re   rf   rg   r0   r_   rD   r`   r8   r]   rj   rY   s   ``` @@@@r=   consume_next_chunk"ChunkedDownload.consume_next_chunk  sN    6 )-(=(=(?%Wg
	 
	  ..t44d6J6J
 	
rm   rx   N
rp   rq   rr   rs   rt   r   ru   rv   r   rw   rx   rm   r=   r   r     s%    > 5522
,
rm   r   c                   P    \ rS rSrSr\R                  \R                  44S jrSr	g)RawChunkedDownloadi$  aR  Download a raw resource in chunks from a Google API.

Args:
    media_url (str): The URL containing the media to be downloaded.
    chunk_size (int): The number of bytes to be retrieved in each
        request.
    stream (IO[bytes]): A write-able stream (i.e. file-like object) that
        will be used to concatenate chunks of the resource as they are
        downloaded.
    start (int): The first byte in a range to be downloaded. If not
        provided, defaults to ``0``.
    end (int): The last byte in a range to be downloaded. If not
        provided, will download to the end of the media.
    headers (Optional[Mapping[str, str]]): Extra headers that should
        be sent with each request, e.g. headers for data encryption
        key headers.

Attributes:
    media_url (str): The URL containing the media to be downloaded.
    start (Optional[int]): The first byte in a range to be downloaded.
    end (Optional[int]): The last byte in a range to be downloaded.
    chunk_size (int): The number of bytes to be retrieved in each request.

Raises:
    ValueError: If ``start`` is negative.
c                    ^ ^^^^^^ T R                  5       u  mmmmUUUU UUU4S jn[        R                  " UT R                  T R                  5      $ )r   c            	      R   > TR                  TTTTSTS9n TR                  U 5        U $ )NT)rC   r8   rE   rD   r   r   s    r=   r`   @RawChunkedDownload.consume_next_chunk.<locals>.retriable_request^  s?    && ' F ""6*Mrm   r   r   s   ``` @@@@r=   r   %RawChunkedDownload.consume_next_chunk@  sN    6 )-(=(=(?%Wg	 	  ..t44d6J6J
 	
rm   rx   Nr   rx   rm   r=   r   r   $  s%    > 5522
-
rm   r   c                    U R                   R                  SS5      R                  5       nUS:X  a%  [        U5      U l        [
        R                  " 5       $ US:X  a0  [        (       a%  [        U5      U l        [
        R                  " 5       $ U$ )aN  Patch the ``_decoder`` on a ``urllib3`` response.

This is so that we can intercept the compressed bytes before they are
decoded.

Only patches if the content encoding is ``gzip`` or ``br``.

Args:
    response_raw (urllib3.response.HTTPResponse): The raw response for
        an HTTP request.
    checksum (object):
        A checksum which will be updated with compressed bytes.

Returns:
    object: Either the original ``checksum`` if ``_decoder`` is not
    patched, or a ``_DoNothingHash`` if the decoder is patched, since the
    caller will no longer need to hash to decoded bytes.
zcontent-encoding r   br)r8   r(   lower_GzipDecoder_decoderr   _DoNothingHash_BrotliDecoder)response_rawr   encodings      r=   r   r   p  sw    & ##''(:B?EEGH6 ,X 6&&((	T	nn .x 8&&((rm   c                   8   ^  \ rS rSrSrU 4S jrU 4S jrSrU =r$ )r   i  a,  Custom subclass of ``urllib3`` decoder for ``gzip``-ed bytes.

Allows a checksum function to see the compressed bytes before they are
decoded. This way the checksum of the compressed value can be computed.

Args:
    checksum (object):
        A checksum which will be updated with compressed bytes.
c                 .   > [         TU ]  5         Xl        g N)super__init__	_checksum)r0   r   	__class__s     r=   r   _GzipDecoder.__init__  s    !rm   c                 X   > U R                   R                  U5        [        TU ]  U5      $ zDecompress the bytes.

Args:
    data (bytes): The compressed bytes to be decompressed.

Returns:
    bytes: The decompressed bytes from ``data``.
)r   r!   r   
decompress)r0   rC   r   s     r=   r   _GzipDecoder.decompress  s'     	d#w!$''rm   )r   )	rp   rq   rr   rs   rt   r   r   rw   __classcell__)r   s   @r=   r   r     s    "
( 
(rm   r   BrotliDecoderc                   *    \ rS rSrSrS rS rS rSrg)r   i  a  Handler for ``brotli`` encoded bytes.

Allows a checksum function to see the compressed bytes before they are
decoded. This way the checksum of the compressed value can be computed.

Because BrotliDecoder's decompress method is dynamically created in
urllib3, a subclass is not practical. Instead, this class creates a
captive urllib3.requests.BrotliDecoder instance and acts as a proxy.

Args:
    checksum (object):
        A checksum which will be updated with compressed bytes.
c                 V    [         R                  R                  5       U l        Xl        g r   )urllib3r1   r   r   r   )r0   r   s     r=   r   _BrotliDecoder.__init__  s    #,,::<DM%Nrm   c                 n    U R                   R                  U5        U R                  R                  U5      $ r   )r   r!   r   r   )r0   rC   s     r=   r   _BrotliDecoder.decompress  s+     NN!!$'==++D11rm   c                 6    U R                   R                  5       $ r   )r   flush)r0   s    r=   r   _BrotliDecoder.flush  s    ==&&((rm   )r   r   N)	rp   rq   rr   rs   rt   r   r   r   rw   rx   rm   r=   r   r     s    		&
	2	)rm   r   )rt   urllib3.responser   r#   google.resumable_mediar   r   r   google.resumable_media.requestsr   r-   rW   r)   RequestsMixinr   RawRequestsMixinrz   r   r   r   r1   GzipDecoderr   hasattrr   rx   rm   r=   <module>r      s    6   , ) + <   Q
--y/A/A Q
hJ
"33Y5G5G J
ZH
&44i6O6O H
VI
)::I<U<U I
X>(7##// (< 7_-- )  )F Nrm   