
    i"                         U d dl Z d dlmZ d dlZd dlZd dlmZm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mZmZmZmZmZ ddlmZ dd	lmZ d
dlmZ  G d de      Zg Zee   ed<   e j@                  d        Z!y)    N)md5)PathPurePosixPath)TemporaryDirectory)sleep)CallableClassVarDictIterableListOptionalTupleUnion   )Client)FileCacheMode   )	LocalPathc            
           e Zd ZU dZdZeee      ed<   ee	e
ej                  f      ed<   dddej                  ddee	e
ej                  f      dee	e
ef      dee	e
ej                  f      d	ee   f fd
Zedefd       Zedefd       Zedefd       ZdddefdZde	e
ej                  f   ddfdZddde	e
ej                  f   defdZdddefdZd)dddefdZd)dddefdZdddee
   fdZ	 d*ddde e!def      fdZ"ddde
fdZ#	 d)dddddeddfdZ$d)dddeddfd Z%dddejL                  fd!Z'd)ddd"eddfd#Z(de	e
ej                  f   ddddfd$Z)ddde*fd%Z+ddde
fd&Z,	 d+ddd'e-de
fd(Z. xZ/S ),LocalClientzAbstract client for accessing objects the local filesystem. Subclasses are as a monkeypatch
    substitutes for normal Client subclasses when writing tests.N_default_storage_temp_dir_local_storage_dir)local_storage_dirfile_cache_modelocal_cache_dircontent_type_methodr   r   r   r   c                8    || _         t        | 	  |||       y )N)r   r   r   )r   super__init__)selfr   r   r   r   argskwargs	__class__s          o/var/www/vps2.regionflexible.com/Desarrollo/venv/lib/python3.12/site-packages/cloudpathlib/local/localclient.pyr   zLocalClient.__init__   s(     #4+ 3+ 	 	
    returnc                     | j                   .t               | _         t        j                  | j                          t	        | j                   j
                        S )a  Return the default storage directory for this client class. This is used if a client
        is instantiated without a storage directory being explicitly provided. In this usage,
        "storage" refers to the local storage that simulates the cloud.
        )r   r   _temp_dirs_to_cleanappendr   nameclss    r$   get_default_storage_dirz#LocalClient.get_default_storage_dir-   sF     ((0,>,@C)&&s'D'DEC116677r%   c                 0    d| _         | j                         S )a3  Reset the default storage directly. This tears down and recreates the directory used by
        default for this client class when instantiating a client without explicitly providing
        a storage directory. In this usage, "storage" refers to the local storage that simulates
        the cloud.
        N)r   r-   r+   s    r$   reset_default_storage_dirz%LocalClient.reset_default_storage_dir8   s     )-%**,,r%   c                 d    | j                   | j                         S t        | j                         S )a  The local directory where files are stored for this client. This storage directory is
        the one that simulates the cloud. If no storage directory was provided on instantiating the
        client, the default storage directory for this client class is used.
        )r   r-   r   )r    s    r$   r   zLocalClient.local_storage_dirB   s2     ""* //11D++,,r%   
cloud_pathr   c                 4    | j                   |j                  z  S N)r   
_no_prefixr    r1   s     r$   _cloud_path_to_localz LocalClient._cloud_path_to_localN   s    %%
(=(===r%   
local_pathc                     t        |      }| j                  j                  j                  }| j	                  | t        |j                  | j                                     S r3   )r   _cloud_meta
path_classcloud_prefix	CloudPathr   relative_tor   )r    r7   r;   s      r$   _local_to_cloud_pathz LocalClient._local_to_cloud_pathQ   sW    *%
''22??~~n]:+A+A$BXBX+YZ[\
 	
r%   c                 r   t        |      }|j                  j                  dd       	 t        j                  | j                  |      |       |S # t        $ r\ t        d       |j                  j                  dd       t        d       t        j                  | j                  |      |       Y |S w xY w)NTexist_okparentsg      ?)r   parentmkdirshutilcopyfiler6   FileNotFoundErrorr   )r    r1   r7   s      r$   _download_filezLocalClient._download_fileX   s    *%
t<	OOOD55jA:N  ! 	O#J##T4#@#JOOD55jA:N	Os   %A A!B65B6c                 @    | j                  |      j                         S r3   )r6   existsr5   s     r$   _existszLocalClient._existsh   s    ((4;;==r%   c                     t        |      }t        j                  dk  r|j                  d        | j	                  |      j
                  di |S N)follow_symlinks)      rN    )dictsysversion_infopopr6   is_dirr    r1   rN   r"   s       r$   _is_dirzLocalClient._is_dirk   sH    o6g%JJ();t((4;;EfEEr%   c                     t        |      }t        j                  dk  r|j                  d        | j	                  |      j
                  di |S rM   )rR   rS   rT   rU   r6   is_filerW   s       r$   _is_filezLocalClient._is_filer   sH    o6g%JJ()<t((4<<FvFFr%   c                 f    | j                  |      ry| j                  |      ryt        d|       )Ndirfilez-Path could not be identified as file or dir: )rX   r[   rG   r5   s     r$   _is_file_or_dirzLocalClient._is_file_or_diry   s5    <<
#]]:&#&ST^S_$`aar%   c              #      K   |rdnd}| j                  |      j                  |      D ]%  }| j                  |      |j                         f ' y w)Nz**/**)r6   globr>   rV   )r    r1   	recursivepatternobjs        r$   	_list_dirzLocalClient._list_dir   sT      &&3,,Z8==gF 	AC,,S13::<@@	As   AAc                 n    t        | j                  |      j                               j                         S r3   )r   r6   
read_bytes	hexdigestr5   s     r$   _md5zLocalClient._md5   s*    4,,Z8CCEFPPRRr%   srcdst
remove_srcc                 ,   | j                  |      j                  j                  dd       |r1| j                  |      j                  | j                  |             |S t	        j
                  | j                  |      | j                  |             |S NTr@   )r6   rC   rD   replacerE   copy)r    rk   rl   rm   s       r$   
_move_filezLocalClient._move_file   s     	!!#&--33T43P%%c*2243L3LS3QR 
 KK11#68Q8QRU8VW
r%   
missing_okc                     | j                  |      }|s|j                         st        d|       |j                         r|j	                          y |j                         rt        j                  |       y y )NzFile does not exist: )r6   rJ   rG   rZ   unlinkrV   rE   rmtree)r    r1   rs   local_storage_paths       r$   _removezLocalClient._remove   sk    !66zB"4";";"=#&;J<$HII%%'%%'&&(MM,- )r%   c                     | j                  |      j                         }t        j                  d d |j                  d d d |j
                  d |j                  d f
      S r3   )r6   statosstat_resultr;   st_sizest_mtime)r    r1   r|   s      r$   _statzLocalClient._stat   sa    //
;@@B~~''##$$
 	
r%   rA   c                     | j                  |      }|j                         r|st        d|       |j                  j	                  dd       |j                          y )NzFile exists: Tr@   )r6   rJ   FileExistsErrorrC   rD   touch)r    r1   rA   rw   s       r$   _touchzLocalClient._touch   sX    !66zB$$&x!M*">??!!''t'D  "r%   c                     | j                  |      }|j                  j                  dd       t        j                  ||       |S ro   )r6   rC   rD   rE   rq   )r    r7   r1   rl   s       r$   _upload_filezLocalClient._upload_file   s?     ''
3

$5J$r%   c                     | j                   d }n| j                   }d |t        | j                  |                  d   iS )Nc                      y)N)NNrQ   )xs    r$   <lambda>z+LocalClient._get_metadata.<locals>.<lambda>   s    r%   content_typer   )r   strr6   )r    r1   r   s      r$   _get_metadatazLocalClient._get_metadata   sM    ##+"8"&":": /D4M4Mj4Y0Z[\]^
 	
r%   c                 "    |j                         S r3   )as_urir5   s     r$   _get_public_urlzLocalClient._get_public_url   s      ""r%   expire_secondsc                     t        d      )Nz1Cannot generate a presigned URL for a local path.)NotImplementedError)r    r1   r   s      r$   _generate_presigned_urlz#LocalClient._generate_presigned_url   s     ""UVVr%   )T)F)i  )0__name__
__module____qualname____doc__r   r	   r   r   __annotations__r   r   r{   PathLike	mimetypes
guess_typer   r   r   classmethodr   r-   r/   propertyr   r6   r>   rH   boolrK   rX   r[   r_   r   r   rf   rj   rr   rx   r|   r   r   r   r
   r   r   intr   __classcell__)r#   s   @r$   r   r      s   D
 IMx1C(DEL !sBKK'7!899
 @D?C=A2;2F2F
 $E#r{{*:$;<
 "%](:";<	

 "%R[[(8"9:
 &h/
" 8 8 8 -$ - - 	-4 	- 	->{ >t >
uS"++5E/F 
; 
 %R[[HXBY ^b  >+ >$ >F+ F FG; G Gb+ b(3- b 27A%A	%T)*	+AS{ Ss S FJ		%0	>B			.+ .4 .4 .
 
 
$# # # #R[[ 01?J		
 	
 	
#+ ## # >EW%W7:W	Wr%   r   r(   c                  :    t         D ]  } | j                           y r3   )r(   cleanup)temp_dirs    r$   clean_temp_dirsr      s    ' r%   )"atexithashlibr   r   r{   pathlibr   r   rE   rS   tempfiler   timer   typingr   r	   r
   r   r   r   r   r   clientr   enumsr   	localpathr   r   r(   r   registerr   rQ   r%   r$   <module>r      sn       	 '  
 '  S S S  !  AW& AWH 13 T,- 2  r%   