
    #HJjO                         d dl Z d dlZ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j"                  d	      Z ed
       G d de             Zy)    N)Path)TemporaryDirectory)AnyOptionalTYPE_CHECKING   )	CloudPathNoStatErrorregister_path_class   )S3ClientzK^s3://(?P<arn>arn:aws:s3::\d{12}:accesspoint/[^/]+\.mrap)(?:/(?P<key>.*))?$s3c                       e Zd ZU dZdZeed<   ded<   eed<   e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fd       Zy
)S3Patha9  Class for representing and operating on AWS S3 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 S3 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 [`S3Client`](../s3client/) class handles authentication with AWS. If a client instance is
    not explicitly specified on `S3Path` instantiation, a default client is used. See `S3Client`'s
    documentation for more details.
    zs3://cloud_prefixr   client_bucket_local_pathreturnc                     | j                   S N)bucketselfs    `/Users/ahmed/devFolder/claude-voice/.venv/lib/python3.12/site-packages/cloudpathlib/s3/s3path.pydrivezS3Path.drive&   s    {{    Nmodec                      y r    )r   parentsexist_okr   s       r   mkdirzS3Path.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S3Path.touch.   st    ;;=%dV&<==KK""4.#%BRWW'AGGIKK$$Q-JJLr   c                 h   	 | j                   j                  |       }t        j                  d d | j                  d d d |j                  dd      d |j                  dd      j                         d f
      S # | j                   j                   j                  j                  $ r t	        d|  d      w xY w)NzNo stats available for z%; it may be a directory or not exist.sizer   last_modified)
r   _get_metadata
exceptions	NoSuchKeyr
   osstat_resultr   get	timestamp)r   follow_symlinksmetas      r   statzS3Path.stat<   s    	;;,,T2D ~~!!#!,668
 	
 {{!!,,66 	)$/TU 	s   A4 4=B1c                    t        | d      r| j                  S t        j                  t	        |             x}r"|j                  d      | _        | j                  S | j                  j                  dd      d   | _        | j                  S )z[The bucket name, or the full MRAP ARN for MRAP paths.

        :type: :class:`str`
        r   arn/r   r   )hasattrr   _MRAP_PATTERNmatchstrgroup
_no_prefixsplit)r   rA   s     r   r   zS3Path.bucketS   sw     4#<<!''D	2252 ;;u-DL ||  ??00a8;DL||r   c                 J    | j                   }|j                  d      r|dd  }|S )Nr>   r   )_no_prefix_no_drive
startswith)r   keys     r   rI   z
S3Path.keya   s+    && >>#ab'C
r   c                 V    | j                   j                  |       j                  d      S )Netag)r   r2   r7   r   s    r   rK   zS3Path.etagl   s"    {{((.226::r   c                     t        | d      r| j                  S | j                  }t        j                  dk(  r|j                  dd      }| j                  j                  |z  | _        | j                  S )Nr   win32:z%3A)r?   r   rD   sysplatformreplacer   _local_cache_dir)r   	no_prefixs     r   _localzS3Path._localp   sb    4'###OO	<<7"!))#u5I;;77)Cr   )FFN)TN)T)__name__
__module____qualname____doc__r   rB   __annotations__r   propertyr   r   r   r#   boolr*   r;   r   rI   rK   rT   r    r   r   r   r      s      L#Ls  # d # 
.    S   ; ;      r   r   )r5   rerO   pathlibr   tempfiler   typingr   r   r   	cloudpathr	   r
   r   s3clientr   compiler@   r   r    r   r   <module>rc      s\    	 	 
  ' / / C C"

R
 Tf Y f  f r   