
    (phN                         S r SSKrSSKJr  SSKJr  SSKJr  SrSr1 Skr	1 S	kr
 " S
 S\R                  5      r " S S\R                  5      r " S S\5      rg)zFModule for file-like access of blobs, usually invoked via Blob.open().    N)RequestRangeNotSatisfiable)DEFAULT_RETRY)ConditionalRetryPolicyi   i  >   retrytimeoutraw_downloadif_generation_matchif_generation_not_matchif_metageneration_matchif_metageneration_not_match>	   r   r   checksumcontent_typepredefined_aclr	   r
   r   r   c                   l    \ rS rSrSrS\4S jrSS jrSS jrSS jr	S r
\S	 5       rS
 rS rS rSrg)
BlobReader7   a  A file-like object that reads from a blob.

:type blob: 'google.cloud.storage.blob.Blob'
:param blob:
    The blob to download.

:type chunk_size: long
:param chunk_size:
    (Optional) The minimum number of bytes to read at a time. If fewer
    bytes than the chunk_size are requested, the remainder is buffered.
    The default is the chunk_size of the blob, or 40MiB.

:type retry: google.api_core.retry.Retry or google.cloud.storage.retry.ConditionalRetryPolicy
:param retry:
    (Optional) How to retry the RPC. A None value will disable
    retries. A google.api_core.retry.Retry value will enable retries,
    and the object will define retriable response codes and errors and
    configure backoff and timeout options.

    A google.cloud.storage.retry.ConditionalRetryPolicy value wraps a
    Retry object and activates it only if certain conditions are met.
    This class exists to provide safe defaults for RPC calls that are
    not technically safe to retry normally (due to potential data
    duplication or other side-effects) but become safe to retry if a
    condition such as if_metageneration_match is set.

    See the retry.py source code and docstrings in this package
    (google.cloud.storage.retry) for information on retry types and how
    to configure them.

    Media operations (downloads and uploads) do not support non-default
    predicates in a Retry object. The default will always be used. Other
    configuration changes for Retry objects such as delays and deadlines
    are respected.

:type download_kwargs: dict
:param download_kwargs:
    Keyword arguments to pass to the underlying API calls.
    The following arguments are supported:

    - ``if_generation_match``
    - ``if_generation_not_match``
    - ``if_metageneration_match``
    - ``if_metageneration_not_match``
    - ``timeout``
    - ``raw_download``

    Note that download_kwargs (excluding ``raw_download``) are also applied to blob.reload(),
    if a reload is needed during seek().
Nc                     U H  nU[         ;  d  M  [        SU S35      e   Xl        SU l        [        R
                  " 5       U l        U=(       d    UR                  =(       d    [        U l	        X0l
        X@l        g )Nz-BlobReader does not support keyword argument .r   )VALID_DOWNLOAD_KWARGS
ValueError_blob_posioBytesIO_buffer
chunk_sizeDEFAULT_CHUNK_SIZE_chunk_size_retry_download_kwargs)selfblobr   r   download_kwargskwargs         N/var/www/html/venv/lib/python3.13/site-packages/google/cloud/storage/fileio.py__init__BlobReader.__init__k   sk    $E11 CE7!L  % 
	zz|%NN<N /    c           	      >   U R                  5         U R                  R                  U5      nU[        U5      -
  nUS:  d  US:  GaF  U =R                  U R                  R                  5       -  sl        [        U5      nU R                  R                  S5        U R                  R                  S5        U R                  nUS:  a  U[        X0R                  5      -   nOS n X R                  R                  " SUUS U R                  S.U R                  D6-  nUS:  aL  [        U5      U:  a=  U R                  R                  X!S  5        U R                  R                  S5        US U nU =R                  [        U5      U-
  -  sl        U$ ! [         a     Nf = f)Nr   )startendr   r    )_checkClosedr   readlenr   tellseektruncatemaxr   r   download_as_bytesr   r    r   write)r!   sizeresultremaining_size	read_sizefetch_start	fetch_ends          r%   r.   BlobReader.ready   sl   ""4(F+AII**,,IFILLa LL!!!$))Kax'#n>N>N*OO	 	
**66 %!!++	
 ++  axCK$.""6%=1!!!$IIVy00I .  s   #7F 
FFc                 $    U R                  U5      $ N)r.   )r!   r6   s     r%   read1BlobReader.read1   s    yyr(   c                 2   U R                  5         U R                  R                  cR  U R                  R	                  5        VVs0 s H  u  p4US:w  d  M  X4_M     nnnU R                  R
                  " S0 UD6  U R                  U R                  R                  5       -   nUS:X  a  UnO*US:X  a  Xa-   nOUS:X  a  U R                  R                  U-   nUS;  a  [        S5      eWU R                  R                  :  a  U R                  R                  nXpR                  :  a@  U R                  R                  S5        U R                  R                  S5        UnXpl        U$ Xv-
  n	U R                  U R                  R                  U	S5      -   nU$ s  snnf )zSeek within the blob.

This implementation of seek() uses knowledge of the blob size to
validate that the reported position does not exceed the blob last byte.
If the blob size is not already known it will call blob.reload().
r   r         >   r   rB   rC   zinvalid whence valuer,   )r-   r   r6   r    itemsreloadr   r   r0   r   r1   r2   )
r!   poswhencekvreload_kwargsinitial_offset
target_posnew_pos
differences
             r%   r1   BlobReader.seek   sd    	::??"!%!6!6!<!<!>!>!~BU!>   JJ..T\\%6%6%88Q;Jq['-Jq[3.J"344

'J 		! LLa LL!!!$ G"I
  $4Jii$,,"3"3J"BBG?s   FFc                 8    U R                   R                  5         g r>   r   closer!   s    r%   rR   BlobReader.close   s    r(   c                 .    U R                   R                  $ r>   r   closedrS   s    r%   rW   BlobReader.closed       ||"""r(   c                     gNTr,   rS   s    r%   readableBlobReader.readable       r(   c                     gNFr,   rS   s    r%   writableBlobReader.writable       r(   c                     gr[   r,   rS   s    r%   seekableBlobReader.seekable   r^   r(   )r   r   r   r    r   r   )r   )__name__
__module____qualname____firstlineno____doc__r   r&   r.   r?   r1   rR   propertyrW   r\   ra   re   __static_attributes__r,   r(   r%   r   r   7   sM    1f )-M 0+Z)V # #r(   r   c                       \ rS rSrSrSS\4S jr\S 5       r\R                  S 5       rS r
S	 rS
 rS rS rS rS rS r\S 5       rS rS rS rSrg)
BlobWriter   a
  A file-like object that writes to a blob.

:type blob: 'google.cloud.storage.blob.Blob'
:param blob:
    The blob to which to write.

:type chunk_size: long
:param chunk_size:
    (Optional) The maximum number of bytes to buffer before sending data
    to the server, and the size of each request when data is sent.
    Writes are implemented as a "resumable upload", so chunk_size for
    writes must be exactly a multiple of 256KiB as with other resumable
    uploads. The default is the chunk_size of the blob, or 40 MiB.

:type ignore_flush: bool
:param ignore_flush:
    Makes flush() do nothing instead of raise an error. flush() without
    closing is not supported by the remote service and therefore calling it
    on this class normally results in io.UnsupportedOperation. However, that
    behavior is incompatible with some consumers and wrappers of file
    objects in Python, such as zipfile.ZipFile or io.TextIOWrapper. Setting
    ignore_flush will cause flush() to successfully do nothing, for
    compatibility with those contexts. The correct way to actually flush
    data to the remote server is to close() (using this object as a context
    manager is recommended).

:type retry: google.api_core.retry.Retry or google.cloud.storage.retry.ConditionalRetryPolicy
:param retry:
    (Optional) How to retry the RPC. A None value will disable
    retries. A google.api_core.retry.Retry value will enable retries,
    and the object will define retriable response codes and errors and
    configure backoff and timeout options.

    A google.cloud.storage.retry.ConditionalRetryPolicy value wraps a
    Retry object and activates it only if certain conditions are met.
    This class exists to provide safe defaults for RPC calls that are
    not technically safe to retry normally (due to potential data
    duplication or other side-effects) but become safe to retry if a
    condition such as if_metageneration_match is set.

    See the retry.py source code and docstrings in this package
    (google.cloud.storage.retry) for information on retry types and how
    to configure them.

    Media operations (downloads and uploads) do not support non-default
    predicates in a Retry object. The default will always be used. Other
    configuration changes for Retry objects such as delays and deadlines
    are respected.

:type upload_kwargs: dict
:param upload_kwargs:
    Keyword arguments to pass to the underlying API
    calls. The following arguments are supported:

    - ``if_generation_match``
    - ``if_generation_not_match``
    - ``if_metageneration_match``
    - ``if_metageneration_not_match``
    - ``timeout``
    - ``content_type``
    - ``predefined_acl``
    - ``checksum``
NFc                     U H  nU[         ;  d  M  [        SU S35      e   Xl        [        5       U l        S U l        U=(       d    UR                  =(       d    [        U l        X0l	        X@l
        XPl        g )Nz-BlobWriter does not support keyword argument r   )VALID_UPLOAD_KWARGSr   r   SlidingBufferr   _upload_and_transportr   r   r   _ignore_flushr   _upload_kwargs)r!   r"   r   ignore_flushr   upload_kwargsr$   s          r%   r&   BlobWriter.__init__&  sr     #E// CE7!L  #
 
$%)" &NN<N)+r(   c                     U R                   $ )zwGet the blob's default chunk size.

:rtype: int or ``NoneType``
:returns: The current blob's chunk size, if it is set.
)_BlobWriter__chunk_sizerS   s    r%   r   BlobWriter._chunk_size=  s        r(   c                 `    Ub%  US:  a  U[         -  S:w  a  [        S[         -  5      eXl        g)zSet the blob's default chunk size.

:type value: int
:param value: (Optional) The current blob's chunk size, if it is set.

:raises: :class:`ValueError` if ``value`` is not ``None`` and is not a
         multiple of 256 KiB.
Nr   z$Chunk size must be a multiple of %d.)CHUNK_SIZE_MULTIPLEr   r}   )r!   values     r%   r   r~   F  s;     u7J/Ja/O69LL  "r(   c                     U R                  5         U R                  R                  U5      n[        U R                  5      U R                  -  nU(       a  U R                  U5        U$ r>   )r-   r   r5   r/   r   _upload_chunks_from_buffer)r!   brF   
num_chunkss       r%   r5   BlobWriter.writeV  sS    ll  # &$*:*::
++J7
r(   c                    U R                   nU R                  R                  SS 5      n[        U[        5      (       aF  U R                  R                  S5      U R                  R                  S5      S.nUR                  US9nU R                  R                  " U R                  R                  R                  U R                  US 4U R                  US.U R                  D6U l        g )Nr   r	   r   )ifGenerationMatchifMetagenerationMatch)query_params)r   r   )r   rx   pop
isinstancer   get"get_retry_policy_if_conditions_metr   _initiate_resumable_uploadbucketclientr   r   rv   )r!   r   r   r   s       r%   _initiate_uploadBlobWriter._initiate_uploadb  s    **..~tD e344 &*%8%8%<%<=R%S)-)<)<)@)@-*L <<,<WE%)ZZ%J%JJJ$$LL	&

 ''&
 !!&
"r(   c                 >   U R                   (       d  U R                  5         U R                   u  p#0 nSU R                  ;   a  SU R                  R                  S5      0n[	        U5       H  nUR
                  " U40 UD6  M     U R                  R                  5         g)z$Upload a specified number of chunks.r   N)rv   r   rx   r   rangetransmit_next_chunkr   flush)r!   r   upload	transportkwargs_s         r%   r   %BlobWriter._upload_chunks_from_buffer~  s     ))!!# 66 +++!4!4!8!8!CDF z"A&&y;F; # 	r(   c                 b    U R                   R                  5       [        U R                   5      -   $ r>   )r   r0   r/   rS   s    r%   r0   BlobWriter.tell  s#    ||  "S%666r(   c                 R    U R                   (       d  [        R                  " S5      eg )NzCannot flush without finalizing upload. Use close() instead, or set ignore_flush=True when constructing this class (see docstring).)rw   r   UnsupportedOperationrS   s    r%   r   BlobWriter.flush  s*     !!))  "r(   c                     U R                   R                  (       d  U R                  S5        U R                   R                  5         g )NrB   )r   rW   r   rR   rS   s    r%   rR   BlobWriter.close  s-    ||""++A.r(   c                     U R                   (       a)  U R                   u  pUR                  UR                  5        U R                  R	                  5         g)zCancel the ResumableUpload.N)rv   delete
upload_urlr   rR   )r!   r   r   s      r%   	terminateBlobWriter.terminate  s=    %% $ : :FV../r(   c                 L    Ub  U R                  5         g U R                  5         g r>   )r   rR   )r!   exc_typeexc_valexc_tbs       r%   __exit__BlobWriter.__exit__  s    NNJJLr(   c                 .    U R                   R                  $ r>   rV   rS   s    r%   rW   BlobWriter.closed  rY   r(   c                     gr`   r,   rS   s    r%   r\   BlobWriter.readable  rc   r(   c                     gr[   r,   rS   s    r%   ra   BlobWriter.writable  r^   r(   c                     gr`   r,   rS   s    r%   re   BlobWriter.seekable  rc   r(   )__chunk_sizer   r   r   rw   r   rv   rx   )ri   rj   rk   rl   rm   r   r&   rn   r   setterr5   r   r   r0   r   rR   r   r   rW   r\   ra   re   ro   r,   r(   r%   rq   rq      s    >F ,. ! ! " "

8,7
 # #r(   rq   c                   b    \ rS rSrSrS rS rSS jrS rS r	S r
S	 rS
 rS r\S 5       rSrg)ru   i  a  A non-rewindable buffer that frees memory of chunks already consumed.

This class is necessary because `google-resumable-media-python` expects
`tell()` to work relative to the start of the file, not relative to a place
in an intermediate buffer. Using this class, we present an external
interface with consistent seek and tell behavior without having to actually
store bytes already sent.

Behavior of this class differs from an ordinary BytesIO buffer. `write()`
will always append to the end of the file only and not change the seek
position otherwise. `flush()` will delete all data already read (data to the
left of the seek position). `tell()` will report the seek position of the
buffer including all deleted data. Additionally the class implements
__len__() which will report the size of the actual underlying buffer.

This class does not attempt to implement the entire Python I/O interface.
c                 F    [         R                  " 5       U l        SU l        g )Nr   )r   r   r   _cursorrS   s    r%   r&   SlidingBuffer.__init__  s    zz|r(   c                 4   U R                  5         U R                  R                  5       nU R                  R                  S[        R
                  5        U R                  R                  U5      nU R                  R                  U5        U R                  U-   $ )z>Append to the end of the buffer without changing the position.r   )r-   r   r0   r1   r   SEEK_ENDr5   r   )r!   r   bookmarkrF   s       r%   r5   SlidingBuffer.write  sm    <<$$&!R[[)ll  #(#||c!!r(   c                     U R                  5         U R                  R                  U5      nU =R                  [	        U5      -  sl        U$ )zRead and move the cursor.)r-   r   r.   r   r/   )r!   r6   datas      r%   r.   SlidingBuffer.read  s9    ||  &D	!r(   c                 0   U R                  5         U R                  R                  5       nU R                  R                  S5        U R                  R	                  S5        U R                  R                  U5        U R                  R                  S5        g)z@Delete already-read data (all data to the left of the position).r   N)r-   r   r.   r1   r2   r5   )r!   leftovers     r%   r   SlidingBuffer.flush  sj     <<$$&!a 8$!r(   c                     U R                   $ )z>Report how many bytes have been read from the buffer in total.)r   rS   s    r%   r0   SlidingBuffer.tell  s    ||r(   c                 d   U R                  5         U R                  R                  5       nXR                  -
  nU R                  R	                  U[
        R                  5      nXB-
  U:X  a  XR                  :  a&  U R                  R	                  U5        [        S5      eXl        U R                  $ )a5  Seek to a position (backwards only) within the internal buffer.

This implementation of seek() verifies that the seek destination is
contained in _buffer. It will raise ValueError if the destination byte
has already been purged from the buffer.

The "whence" argument is not supported in this implementation.
zCannot seek() to that value.)r-   r   r0   r   r1   r   SEEK_CURr   )r!   rF   buffer_initial_posrN   buffer_seek_results        r%   r1   SlidingBuffer.seek  s     	!\\..0<<'
!\\..z2;;G"7:E\\! LL01;<<||r(   c                     U R                   R                  5       nU R                   R                  S[        R                  5      nU R                   R                  U5        U$ )z7Determine the size of the buffer by seeking to the end.r   )r   r0   r1   r   r   )r!   r   lengths      r%   __len__SlidingBuffer.__len__  sE    <<$$&""1bkk2(#r(   c                 6    U R                   R                  5       $ r>   rQ   rS   s    r%   rR   SlidingBuffer.close  s    ||!!##r(   c                 6    U R                   R                  5       $ r>   )r   r-   rS   s    r%   r-   SlidingBuffer._checkClosed  s    ||((**r(   c                 .    U R                   R                  $ r>   rV   rS   s    r%   rW   SlidingBuffer.closed!  rY   r(   )r   r   Nrg   )ri   rj   rk   rl   rm   r&   r5   r.   r   r0   r1   r   rR   r-   rn   rW   ro   r,   r(   r%   ru   ru     sH    $"
4$+ # #r(   ru   )rm   r   google.api_core.exceptionsr   google.cloud.storage.retryr   r   r   r   r   rt   BufferedIOBaser   rq   objectru   r,   r(   r%   <module>r      sm    M 	 A 4 = ! %  
 k"" k\Y"" Yxb#F b#r(   