
    h"                         % S SK r S SKJr  S SKrS SKrS SKJrJr  S SKrS SK	r	S SK
Jr  S SKJr  S SKJrJrJrJrJrJrJrJr  SSKJr  SS	KJr  S
SKJr   " S S\5      r/ r\\   \S'   \ R@                  S 5       r!g)    N)md5)PathPurePosixPath)TemporaryDirectory)sleep)CallableClassVarDictIterableListOptionalTupleUnion   )Client)FileCacheMode   )	LocalPathc            
       F  ^  \ rS rSr% SrSr\\\      \	S'   \\
\\R                  4      \	S'   SSS\R                  S.S\\
\\R                  4      S\\
\\4      S	\\
\\R                  4      S
\\   4U 4S jjjr\S\4S j5       r\S\4S j5       r\S\4S j5       rSSS\4S jrS\
\\R                  4   SS4S jrSSS\
\\R                  4   S\4S jrSSS\4S jrS+SSS\4S jjrS+SSS\4S jjrSSS\\   4S jr  S,SSS\!\"S\4      4S jjr#SSS\4S jr$ S+SSSSS\SS4S jjr%S+SSS \SS4S! jjr&SSS\RN                  4S" jr(S+SSS#\SS4S$ jjr)S\
\\R                  4   SSSS4S% jr*SSS\+4S& jr,SSS\4S' jr- S-SSS(\.S\4S) jjr/S*r0U =r1$ ).LocalClient   zAbstract 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                0   > Xl         [        TU ]	  UUUS9  g )N)r   r   r   )r   super__init__)selfr   r   r   r   argskwargs	__class__s          X/home/james-whalen/.local/lib/python3.13/site-packages/cloudpathlib/local/localclient.pyr    LocalClient.__init__   s&     #4+ 3+ 	 	
    returnc                     U R                   c.  [        5       U l         [        R                  U R                   5        [	        U R                   R
                  5      $ )zReturn 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_dir#LocalClient.get_default_storage_dir-   sF     ((0,>,@C)&&s'D'DEC116677r'   c                 0    SU l         U R                  5       $ )a  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_dir%LocalClient.reset_default_storage_dir8   s     )-%**,,r'   c                 f    U R                   c  U R                  5       $ [        U R                   5      $ )zThe 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   LocalClient.local_storage_dirB   s2     ""* //11D++,,r'   
cloud_pathr   c                 4    U R                   UR                  -  $ N)r   
_no_prefixr!   r6   s     r%   _cloud_path_to_local LocalClient._cloud_path_to_localN   s    %%
(=(===r'   
local_pathc                     [        U5      nU R                  R                  R                  nU R	                  U [        UR                  U R                  5      5       35      $ r8   )r   _cloud_meta
path_classcloud_prefix	CloudPathr   relative_tor   )r!   r=   rA   s      r%   _local_to_cloud_path LocalClient._local_to_cloud_pathQ   sW    *%
''22??~~n]:+A+A$BXBX+YZ[\
 	
r'   c                 l   [        U5      nUR                  R                  SSS9   [        R                  " U R                  U5      U5        U$ ! [         aZ    [        S5        UR                  R                  SSS9  [        S5        [        R                  " U R                  U5      U5         U$ f = f)NTexist_okparentsg      ?)r   parentmkdirshutilcopyfiler;   FileNotFoundErrorr   )r!   r6   r=   s      r%   _download_fileLocalClient._download_fileX   s    *%
t<	OOOD55jA:N  ! 	O#J##T4#@#JOOD55jA:N	Os   &A A B32B3c                 @    U R                  U5      R                  5       $ r8   )r;   existsr:   s     r%   _existsLocalClient._existsh   s    ((4;;==r'   c                     [        US9n[        R                  S:  a  UR                  S5        U R	                  U5      R
                  " S0 UD6$ N)follow_symlinks)      rW    )dictsysversion_infopopr;   is_dirr!   r6   rW   r#   s       r%   _is_dirLocalClient._is_dirk   sF    o6g%JJ()((4;;EfEEr'   c                     [        US9n[        R                  S:  a  UR                  S5        U R	                  U5      R
                  " S0 UD6$ rV   )r[   r\   r]   r^   r;   is_filer`   s       r%   _is_fileLocalClient._is_filer   sF    o6g%JJ()((4<<FvFFr'   c                 z    U R                  U5      (       a  gU R                  U5      (       a  g[        SU 35      e)Ndirfilez-Path could not be identified as file or dir: )ra   re   rN   r:   s     r%   _is_file_or_dirLocalClient._is_file_or_diry   s;    <<
##]]:&&#&ST^S_$`aar'   c              #      #    U(       a  SOSnU R                  U5      R                  U5       H&  nU R                  U5      UR                  5       4v   M(     g 7f)Nz**/**)r;   globrD   r_   )r!   r6   	recursivepatternobjs        r%   	_list_dirLocalClient._list_dir   sM      &&3,,Z8==gFC,,S13::<@@ Gs   AAc                 n    [        U R                  U5      R                  5       5      R                  5       $ r8   )r   r;   
read_bytes	hexdigestr:   s     r%   _md5LocalClient._md5   s*    4,,Z8CCEFPPRRr'   srcdst
remove_srcc                 2   U R                  U5      R                  R                  SSS9  U(       a1  U R                  U5      R                  U R                  U5      5        U$ [        R
                  " U R                  U5      U R                  U5      5        U$ NTrG   )r;   rJ   rK   replacerL   copy)r!   ry   rz   r{   s       r%   
_move_fileLocalClient._move_file   s     	!!#&--33T43P%%c*2243L3LS3QR 
 KK11#68Q8QRU8VW
r'   
missing_okc                    U R                  U5      nU(       d#  UR                  5       (       d  [        SU 35      eUR                  5       (       a  UR	                  5         g UR                  5       (       a  [        R                  " U5        g g )NzFile does not exist: )r;   rR   rN   rd   unlinkr_   rL   rmtree)r!   r6   r   local_storage_paths       r%   _removeLocalClient._remove   st    !66zB"4";";"="=#&;J<$HII%%''%%'&&((MM,- )r'   c                     U R                  U5      R                  5       n[        R                  " S S UR                  S S S UR
                  S UR                  S 4
5      $ r8   )r;   statosstat_resultrA   st_sizest_mtime)r!   r6   r   s      r%   _statLocalClient._stat   sa    //
;@@B~~''##$$
 	
r'   rH   c                     U R                  U5      nUR                  5       (       a  U(       d  [        SU 35      eUR                  R	                  SSS9  UR                  5         g )NzFile exists: TrG   )r;   rR   FileExistsErrorrJ   rK   touch)r!   r6   rH   r   s       r%   _touchLocalClient._touch   s[    !66zB$$&&x!M*">??!!''t'D  "r'   c                     U R                  U5      nUR                  R                  SSS9  [        R                  " X5        U$ r}   )r;   rJ   rK   rL   r   )r!   r=   r6   rz   s       r%   _upload_fileLocalClient._upload_file   s=     ''
3

$5J$r'   c                     U R                   c  S nOU R                   nSU" [        U R                  U5      5      5      S   0$ )Nc                     g)N)NNrZ   )xs    r%   <lambda>+LocalClient._get_metadata.<locals>.<lambda>   s    Lr'   content_typer   )r   strr;   )r!   r6   r   s      r%   _get_metadataLocalClient._get_metadata   sM    ##+"8"&":": /D4M4Mj4Y0Z[\]^
 	
r'   c                 "    UR                  5       $ r8   )as_urir:   s     r%   _get_public_urlLocalClient._get_public_url   s      ""r'   expire_secondsc                     [        S5      e)Nz1Cannot generate a presigned URL for a local path.)NotImplementedError)r!   r6   r   s      r%   _generate_presigned_url#LocalClient._generate_presigned_url   s     ""UVVr'   )r   )T)F)i  )2__name__
__module____qualname____firstlineno____doc__r   r	   r   r   __annotations__r   r   r   PathLike	mimetypes
guess_typer   r   r    classmethodr   r/   r2   propertyr   r;   rD   rO   boolrS   ra   re   rj   r   r   rr   rw   r   r   r   r   r   r   r
   r   r   intr   __static_attributes____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 Wr'   r   r*   c                  >    [          H  n U R                  5         M     g r8   )r*   cleanup)temp_dirs    r%   clean_temp_dirsr      s    ' (r'   )"atexithashlibr   r   r   pathlibr   r   rL   r\   tempfiler   timer   typingr   r	   r
   r   r   r   r   r   clientr   enumsr   	localpathr   r   r*   r   registerr   rZ   r'   r%   <module>r      sn       	 '  
 '  S S S  !  AW& AWH 13 T,- 2  r'   