
    h\7                        S SK J r Jr  S SKrS SKrS SKJrJr  S SKJrJ	r	J
r
JrJrJrJrJr  S SKrSSKJrJr  SSKJr  SSKJr  S	S
KJr   \(       a  S SKJr  S SKJr  S SKJr   S SK!J"r"  S SK#Jr$   S SK#J'r'  \" S5       " S S\5      5       r)\)RT                  \)l        g! \% a    S\S   l&         NAf = f! \( a    Sr' NHf = f)    )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                   N  ^  \ rS rSrSrSSSSSS\R                  SSS4
S\\\	\
R                  4      S\S   S\\	   S\S	   S
\\\	\4      S\\\	\
R                  4      S\\   S\\\	\4      S\\   S\S   4U 4S jjjrS\S\\\	\4      4S jrS\S\\	\
R                  4   S\4S jrS\S\\	   4S jrS\S\4S jrS%S\S\\\\4      4S jjrS&S\S\S\S\4S jjrS&S\S\SS4S jjrS\\	\
R                  4   S\S\4S  jrS\S\	4S! jrS'S\S"\ S\	4S# jjr!S$r"U =r#$ )(GSClient    zClient 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                   > Ub  X@l         OWUb  [        X#S9U l         OEUb  [        R                  " U5      U l         O& [        5       u  p+U=(       d    Un[        X#S9U l         Xl        0 U l        U	b  Xl        U R                  U R                  S'   U
b  Xl	        U R                  U R                  S'   [        TU ]-  UUUS9  g! [         a    [        R
                  " 5       U l          Nf = f)a(  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               R/home/james-whalen/.local/lib/python3.13/site-packages/cloudpathlib/gs/gsclient.pyr1   GSClient.__init__(   s    j %(K$'KQDK$0'AABYZDKF 0C/D,!4_+U 4W0+-")L*.,,DY' %J(,

DW%+ 3+ 	 	
 + F+CCEFs   %C $C+*C+
cloud_pathreturnc                     U R                   R                  UR                  5      nUR                  UR                  5      nUc  g UR                  UR
                  UR                  UR                  UR                  S.$ )N)etagsizeupdatedcontent_typemd5_hash)	r+   bucketget_blobblobr:   r;   r<   r=   r>   r2   r7   r?   rA   s       r5   _get_metadataGSClient._get_metadata   sg    ##J$5$56z/< 				<< $ 1 1 MM     
local_pathc                    U R                   R                  UR                  5      nUR                  UR                  5      n[	        U5      n[
        b0  U R                  b#  [
        R                  " XB40 U R                  D6  U$ [
        c#  U R                  b  [        R                  " S5        UR                  " U40 U R                  D6  U$ )NzwIgnoring `download_chunks_concurrently_kwargs` for version of google-cloud-storage that does not support them (<2.7.0).)r+   r?   r@   rA   r   r   r'   download_chunks_concurrentlywarningswarndownload_to_filenamer/   )r2   r7   rF   r?   rA   s        r5   _download_fileGSClient._download_file   s    ##J$5$56z/*%
'D,T,T,`99$($L$L   'D,T,T,` N %%jED4D4DErE   c                 `   UR                   (       d  gU R                  R                  UR                  5      nUR                  UR                   5      nUb  gUR                   nU(       a  UR	                  S5      (       d  US-  nUR                  SUS9n[        [        U5      5      (       a  gg )Ndirfile/r   )max_resultsprefix)rA   r+   r?   r@   endswith
list_blobsboollist)r2   r7   r?   rA   rS   fs         r5   _is_file_or_dirGSClient._is_file_or_dir   s    ##J$5$56z/__Ffooc22# !!a!?A DG}}rE   c                     UR                   (       d3  U R                  R                  UR                  5      R                  5       $ U R	                  U5      S;   $ )N)rP   rO   )rA   r+   r?   existsrY   )r2   r7   s     r5   _existsGSClient._exists   sC    ;;%%j&7&78??AA##J/?BBrE   c           	   #   h  ^ ^#    TR                   (       d@  U(       a  [        S5      eUU 4S jT R                  R                  5        5        S h  vN   g T R                  R                  TR                   5      nTR                  nU(       a  UR                  S5      (       d  US-  nU(       a  [        5       nUR                  US9 H  n[        UR                  [        U5      S  5      R                   H^  nXu;  d  M
  [        U5      S:w  d  M  T R                  TR                   TR                    SU U 35      S4v   UR                  U5        M`     T R                  TR                   TR                    SUR                   35      S4v   M     g UR                  SUS9nU H=  n	T R                  TR                   TR                    SU	R                   35      S4v   M?     UR                    H3  n
T R                  TR                   TR                    SU
 35      S4v   M5     g  GN7f)	NztCannot recursively list all buckets and contents; you can get all the buckets then recursively list each separately.c              3   x   >#    U  H/  nTR                  TR                   [        U5       35      S 4v   M1     g7f)TN)	CloudPathcloud_prefixstr).0br7   r2   s     r5   	<genexpr>%GSClient._list_dir.<locals>.<genexpr>   s:      3A :#:#:";CF8 DEtL3s   7:rQ   )rS   .TF)	delimiterrS   )r?   NotImplementedErrorr+   list_bucketsrA   rT   setrU   r   namelenparentsrc   ra   rb   addprefixes)r2   r7   	recursiver?   rS   yielded_dirsoparentiteratorrP   	directorys   ``         r5   	_list_dirGSClient._list_dir   s)      ) K 113   ##J$5$56&//#..cMF5L&&f&5+AFF3v;=,ABJJF1c&kS6H NN#-#:#:";J<M<M;NaPVxX^W_ ` !	  %((0 K NNj&=&=%>z?P?P>QQRSTSYSYRZ#[\  6" ((3v(FH !NNj&=&=%>z?P?P>QQRSWS\S\R]#^_  ! &..	NNj&=&=%>z?P?P>QQRS\R]#^_  /Qs    AH2H/B,H2H2DH2srcdst
remove_srcc                    X:X  a  U R                   R                  UR                  5      nUR                  UR                  5      nUR                  c  S[
        R                  " 5       0Ul        O"[
        R                  " 5       UR                  S'   UR                  5         U$ U R                   R                  UR                  5      nU R                   R                  UR                  5      nUR                  UR                  5      nUR                  " XUR                  40 U R                  D6  U(       a  UR                  5         U$ )Nr<   )r+   r?   r@   rA   metadatar   utcnowpatch	copy_blobr/   delete)	r2   rz   r{   r|   r?   rA   
src_bucket
dst_bucketsrc_blobs	            r5   
_move_fileGSClient._move_file   s    :[[''

3F??388,D }}$!*HOO,= >+3??+<i(JJL 
 ++CJJ7J++CJJ7J!**3884H  sxxT4CSCST!
rE   
missing_okc                    U R                  U5      nUS:X  a  U R                  USS9 VVs/ s H  u  pEU(       a  M  UR                  PM     nnnU R                  R	                  UR                  5      nU H"  nUR                  U5      R                  5         M$     g US:X  aO  U R                  R	                  UR                  5      nUR                  UR                  5      R                  5         g U(       d  [        SU 35      eg s  snnf )NrO   T)rr   rP   zFile does not exist: )rY   rx   rA   r+   r?   r@   r   FileNotFoundError)	r2   r7   r   file_or_dirre   is_dirblobsr?   rA   s	            r5   _removeGSClient._remove  s    **:6%(,zT(R(R91Z`(R   [[''
(9(9:F%,,. F"[[''
(9(9:FOOJOO,335 '*?
|(LMM s
   DDc                 4   U R                   R                  UR                  5      nUR                  UR                  5      n0 nU R                  b   U R                  [	        U5      5      u  pgXeS'   UR
                  " [	        U5      40 UDU R                  D6  U$ )Nr=   )r+   r?   rA   r&   rc   upload_from_filenamer/   )r2   rF   r7   r?   rA   
extra_argsr=   _s           r5   _upload_fileGSClient._upload_file   s    ##J$5$56{{:??+
##/"66s:GOL)5~&!!#j/TZT4CSCSTrE   c                     U R                   R                  UR                  5      nUR                  UR                  5      nUR                  $ )N)r+   
get_bucketr?   rA   
public_urlrB   s       r5   _get_public_urlGSClient._get_public_url,  s8    ''
(9(9:{{:??+rE   expire_secondsc                     U R                   R                  UR                  5      nUR                  UR                  5      nUR	                  S[        US9SS9nU$ )Nv4)secondsGET)version
expirationmethod)r+   r   r?   rA   generate_signed_urlr   )r2   r7   r   r?   rA   urls         r5   _generate_presigned_url GSClient._generate_presigned_url1  sV    ''
(9(9:{{:??+&&Y~%Fu ' 
 
rE   )r/   r+   r'   r)   r(   )F)T)i  )$__name__
__module____qualname____firstlineno____doc__	mimetypes
guess_typer   r   rc   osPathLiker   r   r	   r   floatr1   r   rC   r   rL   rY   rV   r]   r
   r   rx   r   r   r   r   intr   __static_attributes____classcell__)r4   s   @r5   r   r       s;    FJ/3!%48?C=A2;2F2FHL#'#'U
!)%R[[0@*A!BU
 m,U
 #	U

 !1U
 "%](:";<U
 "%R[[(8"9:U
 &h/U
 .6d38n-EU
 %U
  U
 U
n 8DcN3K  U3CS=T Y] && Xc] 0C& CT C4F 4vW[|I\@] 4lf 6 t v 2N& Nd Nd N"
uS"++-='> 
F 
W] 
& S 
& # \_  rE   r   )+r   r   r   r   pathlibr   r   typingr   r   r	   r
   r   r   r   r   rI   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   ra    rE   r5   <module>r      s    (  	 ' W W W  2 / ! 
>7/:><5
 tVv V Vr $$I	  >8=D!5>  s$   %B  2B6  B32B36C C