
    i                         d dl Z d dlmZ d dlmZ d dlmZmZmZ ddl	m
Z
mZmZ erddlmZ  ed	       G d
 de
             Zy)    N)Path)TemporaryDirectory)AnyTYPE_CHECKINGOptional   )	CloudPathNoStatErrorregister_path_class   )GSClientgsc                       e Zd ZU dZdZeed<   ded<   edefd       Zdd	e	e
   fd
Zdded	e	e
   fdZddZedefd       Zedefd       Zed        Zede	e   fd       Zy)GSPathaG  Class for representing and operating on Google Cloud Storage URIs, in the style of the
    Python standard library's [`pathlib` module](https://docs.python.org/3/library/pathlib.html).
    Instances represent a path in GS with filesystem path semantics, and convenient methods allow
    for basic operations like joining, reading, writing, iterating over contents, etc. This class
    almost entirely mimics the [`pathlib.Path`](https://docs.python.org/3/library/pathlib.html#pathlib.Path)
    interface, so most familiar properties and methods should be available and behave in the
    expected way.

    The [`GSClient`](../gsclient/) class handles authentication with GCP. If a client instance is
    not explicitly specified on `GSPath` instantiation, a default client is used. See `GSClient`'s
    documentation for more details.
    zgs://cloud_prefixr   clientreturnc                     | j                   S N)bucketselfs    g/var/www/vps2.regionflexible.com/Desarrollo/venv/lib/python3.12/site-packages/cloudpathlib/gs/gspath.pydrivezGSPath.drive   s    {{    Nmodec                      y r    )r   parentsexist_okr   s       r   mkdirzGSPath.mkdir#   s    r   r    c                 :   | j                         r-|st        d|        | j                  j                  | |        y t	               }t        |j                        dz  }|j                          | j                  j                  ||        |j                          y )NzFile exists: empty)
existsFileExistsErrorr   
_move_filer   r   nametouch_upload_filecleanup)r   r    r   tfps        r   r(   zGSPath.touch'   st    ;;=%dV&<==KK""4.#%BRWW'AGGIKK$$Q-JJLr   c                    | j                   j                  |       }|t        d|  d      	 |d   j                         }t        j                  d d | j                  d d d |j                  dd      d |d f
      S # t        $ r d}Y Fw xY w)NzNo stats available for z%; it may be a directory or not exist.updatedr   size)	r   _get_metadatar
   	timestampKeyErrorosstat_resultr   get)r   follow_symlinksmetamtimes       r   statzGSPath.stat5   s    {{((.<)$/TU 	O--/E ~~!!#
 	
  	E	s   A: :BBc                 @    | j                   j                  dd      d   S )N/r   r   )
_no_prefixsplitr   s    r   r   zGSPath.bucketP   s    $$S!,Q//r   c                 J    | j                   }|j                  d      r|dd  }|S )Nr;   r   )_no_prefix_no_drive
startswith)r   keys     r   blobzGSPath.blobT   s+    && >>#ab'C
r   c                 V    | j                   j                  |       j                  d      S )Netagr   r0   r5   r   s    r   rD   zGSPath.etag_   s"    {{((.226::r   c                 b    | j                   j                  |       }|sy |j                  dd       S )Nmd5_hashrE   )r   r7   s     r   md5z
GSPath.md5c   s-    {{((.xx
D))r   )FFN)TN)T)__name__
__module____qualname____doc__r   str__annotations__propertyr   r   r   r!   boolr(   r9   r   rB   rD   rH   r   r   r   r   r      s      L#s  # d # 
6 0 0 0 c   ; ; *Xc] * *r   r   )r3   pathlibr   tempfiler   typingr   r   r   	cloudpathr	   r
   r   gsclientr   r   r   r   r   <module>rV      sE    	  ' / / C C " TZ*Y Z* Z*r   