Ë
    äš¾j\7  ã                   óz  — d dl m Z mZ d dlZd dlZd dlmZmZ d dlmZm	Z	m
Z
mZmZmZmZmZ d dlZddlmZmZ ddlmZ ddlmZ d	d
lmZ 	 er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 dl#m'Z'  ed«       G d„ de«      «       Z)e)jT                  e)_        y# e%$ r ded   _&        Y Œ@w xY w# e($ r dZ'Y ŒFw xY w)é    )ÚdatetimeÚ	timedeltaN)ÚPathÚPurePosixPath)ÚAnyÚCallableÚDictÚIterableÚOptionalÚTYPE_CHECKINGÚTupleÚUnioné   )ÚClientÚregister_client_class)Úimplementation_registry)ÚFileCacheModeé   )ÚGSPath)ÚCredentials)ÚRetry)Údefault)ÚDefaultCredentialsError)r   FÚgs)Útransfer_managerc                   ó$  ‡ — e Zd ZdZddddddej
                  dddf
deeee	j                  f      ded   dee   ded   d	eeeef      d
eeee	j                  f      dee   deeeef      dee   ded   fˆ fd„Zdedeeeef      fd„Zdedeee	j                  f   defd„Zdedee   fd„Zdedefd„Zd#dedeeeef      fd„Zd$dedededefd„Zd$dededdfd„Zdeee	j                  f   dedefd„Zdedefd „Zd%ded!edefd"„Z ˆ xZ!S )&ÚGSClienta  Client class for Google Cloud Storage which handles authentication with GCP for
    [`GSPath`](../gspath/) instances. See documentation for the
    [`__init__` method][cloudpathlib.gs.gsclient.GSClient.__init__] for detailed authentication
    options.
    NÚapplication_credentialsÚcredentialsr   ÚprojectÚstorage_clientÚStorageClientÚfile_cache_modeÚlocal_cache_dirÚcontent_type_methodÚ#download_chunks_concurrently_kwargsÚtimeoutÚretryr   c                 óâ  •— |�|| _         nX|�t        ||¬«      | _         nC|�t        j                  |«      | _         n&	 t        «       \  }}|xs |}t        ||¬«      | _         || _        i | _        |	� |	| _        | j                  | j                  d<   |
� |
| _	        | j                  | j                  d<   t        ‰| �-  |||¬«       y# t        $ r t        j
                  «       | _         Y Œ‰w xY w)a8  Class constructor. Sets up a [`Storage
        Client`](https://googleapis.dev/python/storage/latest/client.html).
        Supports, in this order, the following authentication methods of `Storage Client`.

        - Instantiated and already authenticated `Storage Client`.
        - OAuth2 Credentials object and a project name.
        - File path to a JSON credentials file for a Google service account.
        - Google Cloud SDK default credentials. See [How Application Default Credentials works](https://cloud.google.com/docs/authentication/application-default-credentials)

        If no authentication methods are used,
        then the client will be instantiated as anonymous, which will only have
        access to public buckets.

        Args:
            application_credentials (Optional[Union[str, os.PathLike]]): Path to Google service
                account credentials file.
            credentials (Optional[Credentials]): The OAuth2 Credentials to use for this client.
                See documentation for [`StorageClient`](
                https://googleapis.dev/python/storage/latest/client.html).
            project (Optional[str]): The project which the client acts on behalf of. See
                documentation for [`StorageClient`](
                https://googleapis.dev/python/storage/latest/client.html).
            storage_client (Optional[StorageClient]): Instantiated [`StorageClient`](
                https://googleapis.dev/python/storage/latest/client.html).
            file_cache_mode (Optional[Union[str, FileCacheMode]]): How often to clear the file cache; see
                [the caching docs](https://cloudpathlib.drivendata.org/stable/caching/) for more information
                about the options in cloudpathlib.eums.FileCacheMode.
            local_cache_dir (Optional[Union[str, os.PathLike]]): Path to directory to use as cache
                for downloaded files. If None, will use a temporary directory. Default can be set with
                the `CLOUDPATHLIB_LOCAL_CACHE_DIR` environment variable.
            content_type_method (Optional[Callable]): Function to call to guess media type (mimetype) when
                writing a file to the cloud. Defaults to `mimetypes.guess_type`. Must return a tuple (content type, content encoding).
            download_chunks_concurrently_kwargs (Optional[Dict[str, Any]]): Keyword arguments to pass to
                [`download_chunks_concurrently`](https://cloud.google.com/python/docs/reference/storage/latest/google.cloud.storage.transfer_manager#google_cloud_storage_transfer_manager_download_chunks_concurrently)
                for sliced parallel downloads; Only available in `google-cloud-storage` version 2.7.0 or later, otherwise ignored and a warning is emitted.
            timeout (Optional[float]): Cloud Storage [timeout value](https://cloud.google.com/python/docs/reference/storage/1.39.0/retry_timeout)
            retry (Optional[google.api_core.retry.Retry]): Cloud Storage [retry configuration](https://cloud.google.com/python/docs/reference/storage/1.39.0/retry_timeout#configuring-retries)
        N)r   r    r'   r(   )r$   r%   r#   )Úclientr"   Úfrom_service_account_jsonÚgoogle_default_authr   Úcreate_anonymous_clientr&   Úblob_kwargsr'   r(   ÚsuperÚ__init__)Úselfr   r   r    r!   r#   r$   r%   r&   r'   r(   Údefault_projectÚ	__class__s               €úb/home/spazio/kingdom_calls/work5/transenv/lib/python3.12/site-packages/cloudpathlib/gs/gsclient.pyr0   zGSClient.__init__(   s  ø€ ðj Ð%Ø(ˆD�KàÐ$Ü'°KÈÔQˆD�Kà$Ð0Ü'×AÑAÐBYÓZˆD�KðFô 0CÓ/DÑ,�˜_Ø!Ò4 _�Ü+¸ÈWÔU�”ð 4WˆÔ0Ø+-ˆÔØÐØ")ˆDŒLØ*.¯,©,ˆD×Ñ˜YÑ'ØÐØ %ˆDŒJØ(,¯
©
ˆD×Ñ˜WÑ%ä‰ÑØ+Ø 3Ø+ð 	õ 	
øô +ò FÜ+×CÑCÓE�–ðFús   ¿%C	 Ã	"C.Ã-C.Ú
cloud_pathÚreturnc                 óü   — | j                   j                  |j                  «      }|j                  |j                  «      }|€y |j                  |j
                  |j                  |j                  |j                  dœS )N)ÚetagÚsizeÚupdatedÚcontent_typeÚmd5_hash)	r*   ÚbucketÚget_blobÚblobr8   r9   r:   r;   r<   ©r1   r5   r=   r?   s       r4   Ú_get_metadatazGSClient._get_metadata   sg   € Ø—‘×#Ñ# J×$5Ñ$5Ó6ˆØ�‰˜zŸ™Ó/ˆàˆ<Øð Ÿ	™	ØŸ	™	ØŸ<™<Ø $× 1Ñ 1Ø ŸM™Mñð ó    Ú
local_pathc                 óŽ  — | j                   j                  |j                  «      }|j                  |j                  «      }t	        |«      }t
        �/| j                  �#t        j                  ||fi | j                  ¤Ž |S t
        €!| j                  �t        j                  d«        |j                  |fi | j                  ¤Ž |S )NzwIgnoring `download_chunks_concurrently_kwargs` for version of google-cloud-storage that does not support them (<2.7.0).)r*   r=   r>   r?   r   r   r&   Údownload_chunks_concurrentlyÚwarningsÚwarnÚdownload_to_filenamer.   )r1   r5   rC   r=   r?   s        r4   Ú_download_filezGSClient._download_fileŽ   sº   € Ø—‘×#Ñ# J×$5Ñ$5Ó6ˆØ�‰˜zŸ™Ó/ˆä˜*Ó%ˆ
ÜÐ'¨D×,TÑ,TÐ,`Ü×9Ñ9Ø�jñØ$(×$LÑ$Lòð Ðô  Ð'¨D×,TÑ,TÐ,`Ü—‘ð Nôð &ˆD×%Ñ% jÑE°D×4DÑ4DÒEàÐrB   c                 ó<  — |j                   sy| j                  j                  |j                  «      }|j                  |j                   «      }|�y|j                   }|r|j	                  d«      s|dz  }|j                  d|¬«      }t        t        |«      «      ryy )NÚdirÚfileú/r   )Úmax_resultsÚprefix)r?   r*   r=   r>   ÚendswithÚ
list_blobsÚboolÚlist)r1   r5   r=   r?   rO   Úfs         r4   Ú_is_file_or_dirzGSClient._is_file_or_dir¡   s‹   € à�ŠØà—‘×#Ñ# J×$5Ñ$5Ó6ˆØ�‰˜zŸ™Ó/ˆàÐØà—_‘_ˆFÙ˜fŸo™o¨cÔ2Ø˜#‘�ð ×!Ñ!¨a¸Ð!Ó?ˆAô ”D˜“GŒ}ØàrB   c                 ó¦   — |j                   s3| j                  j                  |j                  «      j                  «       S | j	                  |«      dv S )N)rL   rK   )r?   r*   r=   ÚexistsrU   )r1   r5   s     r4   Ú_existszGSClient._exists¹   sC   € à�ŠØ—;‘;×%Ñ% j×&7Ñ&7Ó8×?Ñ?ÓAÐAà×#Ñ# JÓ/°?ÐBÐBrB   c           	   #   ó(  ‡ ‡K  — ‰j                   s:|rt        d«      ‚ˆˆ fd„‰ j                  j                  «       D «       E d {  –—†  y ‰ j                  j                  ‰j                   «      }‰j                  }|r|j                  d«      s|dz  }|rãt        «       }|j                  |¬«      D ]Ã  }t        |j                  t        |«      d  «      j                  D ]Y  }||vsŒt        |«      dk7  sŒ‰ j                  ‰j                  › ‰j                   › d|› |› �«      df–— |j                  |«       Œ[ ‰ j                  ‰j                  › ‰j                   › d|j                  › �«      df–— ŒÅ y |j                  d|¬«      }|D ]<  }	‰ j                  ‰j                  › ‰j                   › d|	j                  › �«      df–— Œ> |j                   D ]2  }
‰ j                  ‰j                  › ‰j                   › d|
› �«      df–— Œ4 y 7 �ŒÊ­w)	NztCannot recursively list all buckets and contents; you can get all the buckets then recursively list each separately.c              3   ór   •K  — | ].  }‰j                  ‰j                  › t        |«      › �«      d f–— Œ0 y­w)TN)Ú	CloudPathÚcloud_prefixÚstr)Ú.0Úbr5   r1   s     €€r4   ú	<genexpr>z%GSClient._list_dir.<locals>.<genexpr>È   s;   øè ø€ ò àð —‘ :×#:Ñ#:Ð";¼CÀ»F¸8Ð DÓEÀtÔLñùs   ƒ47rM   )rO   ú.TF)Ú	delimiterrO   )r=   ÚNotImplementedErrorr*   Úlist_bucketsr?   rP   ÚsetrQ   r   ÚnameÚlenÚparentsr]   r[   r\   ÚaddÚprefixes)r1   r5   Ú	recursiver=   rO   Úyielded_dirsÚoÚparentÚiteratorrL   Ú	directorys   ``         r4   Ú	_list_dirzGSClient._list_dirÀ   s<  ùè ø€ à× Ò ÙÜ)ð Kóð ôàŸ™×1Ñ1Ó3ô÷ ð ð à—‘×#Ñ# J×$5Ñ$5Ó6ˆà—‘ˆÙ˜&Ÿ/™/¨#Ô.Ø�c‰MˆFÙÜ›5ˆLØ×&Ñ&¨fÐ&Ó5ò �ä+¨A¯F©F´3°v³;°=Ð,AÓB×JÑJò 	1�Fà \Ò1´c¸&³kÀSÓ6Hà ŸN™NØ#-×#:Ñ#:Ð";¸J×<MÑ<MÐ;NÈaÐPVÈxÐX^ÐW_Ð `óð !ð	ò ð %×(Ñ(¨Õ0ð	1ð —N‘N j×&=Ñ&=Ð%>¸z×?PÑ?PÐ>QÐQRÐST×SYÑSYÐRZÐ#[Ó\Øðó ñð" ×(Ñ(°3¸vÐ(ÓFˆHð !ò �à—N‘N j×&=Ñ&=Ð%>¸z×?PÑ?PÐ>QÐQRÐSW×S\ÑS\ÐR]Ð#^Ó_Øðó ðð &×.Ñ.ò �	à—N‘N j×&=Ñ&=Ð%>¸z×?PÑ?PÐ>QÐQRÐS\ÐR]Ð#^Ó_Øðó ñðQûs    „AHÁHÁB!HÃ(HÃ7DHÚsrcÚdstÚ
remove_srcc                 ó†  — ||k(  r›| j                   j                  |j                  «      }|j                  |j                  «      }|j                  €dt        j                  «       i|_        n!t        j                  «       |j                  d<   |j                  «        |S | j                   j                  |j                  «      }| j                   j                  |j                  «      }|j                  |j                  «      } |j                  |||j                  fi | j                  ¤Ž |r|j                  «        |S )Nr:   )r*   r=   r>   r?   Úmetadatar   ÚutcnowÚpatchÚ	copy_blobr.   Údelete)	r1   rr   rs   rt   r=   r?   Ú
src_bucketÚ
dst_bucketÚsrc_blobs	            r4   Ú
_move_filezGSClient._move_fileö   sò   € à�#Š:Ø—[‘[×'Ñ'¨¯
©
Ó3ˆFØ—?‘? 3§8¡8Ó,ˆDð �}‰}Ð$Ø!*¬H¯O©OÓ,=Ð >�•ä+3¯?©?Ó+<�—‘˜iÑ(Ø�J‰JŒLð ˆ
ð Ÿ™×+Ñ+¨C¯J©JÓ7ˆJØŸ™×+Ñ+¨C¯J©JÓ7ˆJà!×*Ñ*¨3¯8©8Ó4ˆHØ ˆJ× Ñ  ¨:°s·x±xÑTÀ4×CSÑCSÒTáØ—‘Ô!àˆ
rB   Ú
missing_okc                 ó   — | j                  |«      }|dk(  r~| j                  |d¬«      D ��cg c]  \  }}|rŒ	|j                  ‘Œ }}}| j                  j	                  |j                  «      }|D ]!  }|j                  |«      j                  «        Œ# y |dk(  rO| j                  j	                  |j                  «      }|j                  |j                  «      j                  «        y |st        d|› �«      ‚y c c}}w )NrK   T)rk   rL   zFile does not exist: )rU   rq   r?   r*   r=   r>   rz   ÚFileNotFoundError)	r1   r5   r   Úfile_or_dirr_   Úis_dirÚblobsr=   r?   s	            r4   Ú_removezGSClient._remove  sé   € Ø×*Ñ*¨:Ó6ˆØ˜%Òà(,¯©°zÈT¨Ó(R÷Ù$˜1˜fÒZ`�—“ðˆEñ ð —[‘[×'Ñ'¨
×(9Ñ(9Ó:ˆFØò /�Ø—‘ Ó%×,Ñ,Õ.ñ/à˜FÒ"Ø—[‘[×'Ñ'¨
×(9Ñ(9Ó:ˆFØ�O‰O˜JŸO™OÓ,×3Ñ3Õ5ñ Ü'Ð*?À
¸|Ð(LÓMÐMð ùós
   ­
C:¸C:c                 ó6  — | j                   j                  |j                  «      }|j                  |j                  «      }i }| j                  �"| j                  t	        |«      «      \  }}||d<    |j
                  t	        |«      fi |¤| j                  ¤Ž |S )Nr;   )r*   r=   r?   r%   r]   Úupload_from_filenamer.   )r1   rC   r5   r=   r?   Ú
extra_argsr;   Ú_s           r4   Ú_upload_filezGSClient._upload_file   s‹   € Ø—‘×#Ñ# J×$5Ñ$5Ó6ˆØ�{‰{˜:Ÿ?™?Ó+ˆàˆ
Ø×#Ñ#Ð/Ø"×6Ñ6´s¸:³ÓG‰OˆL˜!Ø)5ˆJ�~Ñ&à!ˆ×!Ñ!¤# j£/ÑT°ZÐTÀ4×CSÑCSÒTØÐrB   c                 óš   — | j                   j                  |j                  «      }|j                  |j                  «      }|j                  S )N)r*   Ú
get_bucketr=   r?   Ú
public_urlr@   s       r4   Ú_get_public_urlzGSClient._get_public_url,  s8   € Ø—‘×'Ñ'¨
×(9Ñ(9Ó:ˆØ�{‰{˜:Ÿ?™?Ó+ˆØ�‰ÐrB   Úexpire_secondsc                 óÂ   — | j                   j                  |j                  «      }|j                  |j                  «      }|j	                  dt        |¬«      d¬«      }|S )NÚv4)ÚsecondsÚGET)ÚversionÚ
expirationÚmethod)r*   rŒ   r=   r?   Úgenerate_signed_urlr   )r1   r5   r�   r=   r?   Úurls         r4   Ú_generate_presigned_urlz GSClient._generate_presigned_url1  sV   € Ø—‘×'Ñ'¨
×(9Ñ(9Ó:ˆØ�{‰{˜:Ÿ?™?Ó+ˆØ×&Ñ&Ø¤Y°~Ô%FÈuð 'ó 
ˆð ˆ
rB   )F)T)i  )"Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú	mimetypesÚ
guess_typer   r   r]   ÚosÚPathLiker   r   r	   r   Úfloatr0   r   rA   r   rI   rU   rR   rX   r
   r   rq   r~   r…   rŠ   rŽ   Úintr™   Ú__classcell__)r3   s   @r4   r   r       s0  ø„ ñð FJØ/3Ø!%Ø48Ø?CØ=AØ2;×2FÑ2FØHLØ#'Ø#'ñU
à!)¨%°°R·[±[Ð0@Ñ*AÑ!BðU
ð ˜mÑ,ðU
ð ˜#‘ð	U
ð
 ! Ñ1ðU
ð " %¨¨]Ð(:Ñ";Ñ<ðU
ð " %¨¨R¯[©[Ð(8Ñ"9Ñ:ðU
ð & hÑ/ðU
ð .6°d¸3À¸8±nÑ-EðU
ð ˜%‘ðU
ð ˜Ñ õU
ðn¨ð °8¸DÀÀcÀ¹NÑ3Kó ð¨ð ¸UÀ3ÈÏÉÐCSÑ=Tð ÐY]ó ð&¨&ð °X¸c±]ó ð0C &ð C¨Tó Cñ4 Fð 4ÀÈÈvÐW[È|ÑI\Ñ@]ó 4ñl˜fð ¨6ð ¸tð Èvó ñ2N &ð N°dð NÀdó Nð"
 u¨S°"·+±+Ð-=Ñ'>ð 
ÈFð 
ÐW]ó 
ð¨&ð °Só ñ
°&ð È#ð Ð\_÷ rB   r   )+r   r   rž   r    Úpathlibr   r   Útypingr   r   r	   r
   r   r   r   r   rF   r*   r   r   Ú	cloudpathr   Úenumsr   Úgspathr   Úgoogle.auth.credentialsr   Úgoogle.api_core.retryr   Úgoogle.authr   r,   Úgoogle.auth.exceptionsr   Úgoogle.cloud.storager"   ÚModuleNotFoundErrorÚdependencies_loadedr   ÚImportErrorr   r[   © rB   r4   ú<module>r³      s±   ðß (Û Û 	ß 'ß W× WÓ WÛ ç 2Ý /Ý !Ý ð
>ÙÝ7Ý/å:Ý>Ý<ðÝ5ñ
 �tÓôVˆvó Vó ðVðr ×$Ñ$€…øðI	 ò >Ø8=Ð˜DÑ!Ö5ð>ûð ò ØÒðús$   Á B Á-B0 ÂB-Â,B-Â0B:Â9B: